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

      

  • 相关阅读:
    ACM HDU 3622 Bomb Game(2SAT)
    ACM HDU 3353 Not So Flat After All(简单题)
    php安装pear
    基于CPU访存局部性原理下的矩阵乘法实现
    MATLAB常用操作大全
    Matlab中二维统计分析图和三维立体图
    EXCEL中ABS
    图片和文本实现的数据隐藏
    NYOJ 485
    MATLAB解方程与函数极值
  • 原文地址:https://www.cnblogs.com/xhrr/p/tabBarController.html
Copyright © 2011-2022 走看看