import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'bicycleCharge.dart';
import 'carCharg.dart';
class TabsPage extends StatefulWidget{
@override
_TabsPageState createState() => new _TabsPageState();
}
class _TabsPageState extends State<TabsPage> with SingleTickerProviderStateMixin{
TabController _tabController;
//①初始化,一加载便会触发该方法
void initState(){
super.initState();
_tabController = new TabController(
vsync: this,
length: 2,
);
}
@override
Widget build(BuildContext context){
//初始化
ScreenUtil.instance = ScreenUtil( 750, height: 1334)..init(context);
return DefaultTabController(
length: 2,
child: Scaffold(
appBar: appBar(),
body: Stack(
children: <Widget>[
TabBarView(
controller: this._tabController,//③
children: <Widget>[
ElectricBicycle(),
CarCharge(),
],
),
],
),
drawer: Container(
padding: EdgeInsets.only(left: 80, right: 10),
color: Colors.white,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('个人中心')
],
),
),
),
);
}
// appBar
Widget appBar(){
return AppBar(
centerTitle: true,
leading: IconButton(
icon: Icon(
Icons.person,
color: Color.fromRGBO(46, 48, 56, 1),
),
onPressed: (){
debugPrint('ddddd');
Scaffold.of(context).openDrawer();
},
),
title: Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'XXXXXX',
style: TextStyle(
color: Colors.black,
),
textAlign: TextAlign.right,
),
IconButton(
alignment: Alignment.centerLeft,
icon: Icon(
Icons.arrow_drop_down,
color: Color.fromRGBO(46, 48, 56, 1),
),
onPressed: (){
debugPrint('down');
},
),
],
),
),
actions: <Widget>[
Container(
ScreenUtil.getInstance().setWidth(60),
height: ScreenUtil.getInstance().setHeight(60),
child: IconButton(
icon: Image.asset('assets/icons/icon_title_msg.png'),
onPressed: (){
debugPrint('down');
},
),
),
],
elevation: 0,
bottom: TabBar(
controller: this._tabController,//②
isScrollable: true,
indicator: const BoxDecoration(),
unselectedLabelColor: Color.fromRGBO(46, 48, 56, 1),
indicatorColor: Colors.black54,
indicatorSize: TabBarIndicatorSize.label,
// indicatorWeight: 1.0,
labelColor: Colors.black,
tabs: <Widget>[
Tab(
child: Text(
'tabA',
style: TextStyle(
fontSize: ScreenUtil.getInstance().setSp(38)
),
),
),
Tab(
child: Text(
'tabB',
style: TextStyle(
fontSize: ScreenUtil.getInstance().setSp(38)
),
),
),
],
),
backgroundColor: Colors.white,
);
}
}