基本使用:

import 'package:flutter/material.dart';

class TabBarControllerPage extends StatefulWidget {
  TabBarControllerPage({Key key}) : super(key: key);

  _TabBarControllerPageState createState() => _TabBarControllerPageState();
}

class _TabBarControllerPageState extends State<TabBarControllerPage> with SingleTickerProviderStateMixin{
  TabController _tabController;
  @override
  void dispose(){ //生命周期函数:
  super.dispose();
  _tabController.dispose();
  }
  @override
  void initState(){  //生命周期函数:
    super.initState();
    _tabController=new TabController(
      vsync: this,
      length: 2
    );
    _tabController.addListener((){
      print(_tabController.index);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('TabBarControllerPage'),
        bottom: TabBar(
          controller:this._tabController,
          tabs: <Widget>[
            Tab(text: '热销'),
            Tab(text: '推荐')
          ],
        ),
      ),
      body: TabBarView(
        controller: this._tabController,
        children: <Widget>[
          Center(child: Text('热销')),
          Center(child: Text('推荐'))
        ],
      )

    );
  }
}

 

相关文章:

  • 2021-05-28
  • 2022-01-19
  • 2021-12-14
  • 2021-12-21
  • 2021-08-30
  • 2021-05-04
  • 2021-09-01
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-27
  • 2022-12-23
  • 2021-10-16
  • 2023-03-19
相关资源
相似解决方案