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 49 50 51 52 53 54
| class _PageTestState extends State<PageTest> with TickerProviderStateMixin { late PageController _pageController; int _bottomNavigationBarIndex = 0;
@override void initState() { _pageController = PageController(); super.initState(); }
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text( "若轻视频", style: TextStyle(color: Colors.white), ), ), bottomNavigationBar: BottomNavigationBar( items: const <BottomNavigationBarItem>[ BottomNavigationBarItem(icon: Icon(Icons.tv), label: "电视"), BottomNavigationBarItem( icon: Icon(Icons.ondemand_video_sharp), label: "视频") ], currentIndex: _bottomNavigationBarIndex, onTap: _onBottomNavigationBarTapped, ), body: PageView( controller: _pageController, onPageChanged: _changeBottomNavigationBar, children: const [ Text("1"), Text("2"), ], )); }
void _onBottomNavigationBarTapped(int index) { _pageController.animateToPage(index, duration: const Duration(milliseconds: 500), curve: Curves.ease); }
void _changeBottomNavigationBar(int index) { setState(() { _bottomNavigationBarIndex = index; }); } }
|