其他分享
首页 > 其他分享> > Flutter 自定义Controller

Flutter 自定义Controller

作者:互联网

// import 'dart:html';

import 'package:flutter/material.dart';


/**
 * 注意在这里必须要继承的有状态的组件以及
 * 要混入一个别的组件SingleTickerProviderStateMixin剩下的必须要实例化一个TabController
 *
 */


class TabBarsController extends StatefulWidget {
  @override
  _TabBarsControllerState createState() => _TabBarsControllerState();
}

class _TabBarsControllerState extends State<TabBarsController> with SingleTickerProviderStateMixin{

  TabController _tabController;

  @override
    void initState(){
        super.initState();
        _tabController=new TabController(vsync: this,length: 3 );
        _tabController.addListener(() {
            print(_tabController.index);
        });
    }
    
  
  @override
  Widget build(BuildContext context) {
    /**
     * 这个的结构必须是MaterilApp的下面和Scaffole的上面
     */
    return Scaffold(
      appBar: AppBar(

        title: Text('tabContro'),
        bottom: TabBar(
          controller: this._tabController,
          tabs: <Widget>[
            Tab(text: 'c1'),
            Tab(text: 'c2'),
            Tab(text: 'c3'),
          ],
        ),
      ),
      body: TabBarView(
        controller: this._tabController,
        children:<Widget>[
          Text('c1'),
          Text('c2'),
          Text('c3')
        ],
      ),
    );
  }
}

 

标签:Tab,自定义,Text,tabController,Controller,TabController,text,override,Flutter
来源: https://blog.csdn.net/qq_42577176/article/details/115210484