1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| class _TabTestState extends State<TabTest> with TickerProviderStateMixin { final List<String> _tabs = ["首页", "动画"]; late TabController _controller;
@override void initState() { _controller = TabController(length: _tabs.length, vsync: this); super.initState(); }
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text( "若轻视频", style: TextStyle(color: Colors.white), ), actions: const [], bottom: PreferredSize( preferredSize: const Size.fromHeight(40), child: Align( alignment: Alignment.centerLeft, child: TabBar( controller: _controller, isScrollable: true, padding: const EdgeInsets.only(left: 10.0, right: 10.0), tabs: _tabs .map((e) => Tab( child: Text( e, style: const TextStyle(color: Colors.white), ))) .toList(), ), ), )), body: TabBarView( controller: _controller, children: _tabs.map((e) { return KeepAliveWrapper(child: Text(e)); }).toList(), )); } }
|