zoukankan      html  css  js  c++  java
  • tabBarController

    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,
          );
      }
    }
    

      

  • 相关阅读:
    【CV论文阅读】Detecting events and key actors in multi-person videos
    2020意大利数学奥林匹克 第6题
    2020最终数学杯 初级组第3题
    地球上的最短距离
    钱学森做过的趣题
    第35届IMO预选题(瑞典提供)
    第55届IMO 第2题
    第四十届(1999年)IMO 第3题(白俄罗斯供题)
    2019年多瑙河数学竞赛(高中组) 第三题
    2020环球城市春季赛 O级别 高级组 第2题
  • 原文地址:https://www.cnblogs.com/xhrr/p/tabBarController.html
Copyright © 2011-2022 走看看