TabBarController 动态实现导航栏切换
作者:互联网
import 'package:flutter/material.dart';
class TabBarControllerPage extends StatefulWidget { TabBarControllerPage({Key? key}) : super(key: key);
@override _TabBarControllerPageState createState() => _TabBarControllerPageState(); }
class _TabBarControllerPageState extends State<TabBarControllerPage> with SingleTickerProviderStateMixin { late TabController _tabController;
@override void initState() { // 生命周期函数 super.initState(); _tabController = new TabController( length: 2, vsync: this, ); // 监听tab点击 _tabController.addListener(() { print(_tabController.index); }); }
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("TabBarControllerPage"), bottom: TabBar( controller: this._tabController, tabs: [ Tab(text: '热销'), Tab(text: '推荐'), ], ), ), body: TabBarView( controller: this._tabController, children: [ Center( child: Text("热销"), ), Center( child: Text("推荐"), ), ], )); } }
标签:TabBarControllerPageState,Text,tabController,override,切换,key,TabBarController,导航 来源: https://www.cnblogs.com/eric-share/p/15096445.html