import 'package:flutter/material.dart'; import 'package:gobang/pages/home_page.dart'; import 'package:gobang/pages/mine_page.dart'; /// Description: index page /// Time : 02/21/2024 Wednesday /// Author : liuyuqi.gov@msn.cn class IndexPage extends StatefulWidget { const IndexPage({Key? key}) : super(key: key); @override State createState() => _IndexPageState(); } class _IndexPageState extends State { final List bottomTabs = const [ BottomNavigationBarItem(icon: Icon(Icons.home), label: '出行'), BottomNavigationBarItem(icon: Icon(Icons.business), label: '大厅'), BottomNavigationBarItem(icon: Icon(Icons.school), label: '消息'), BottomNavigationBarItem(icon: Icon(Icons.school), label: '我的'), ]; final List pages = [ HomePage(), MinePage(), ]; int currentIndex = 0; Size get size => MediaQuery.of(context).size; final pageController = PageController(); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( actions: [Icon(Icons.search)], title: Text("gobang"), ), // drawer: , bottomNavigationBar: BottomNavigationBar( items: bottomTabs, currentIndex: currentIndex, type: BottomNavigationBarType.fixed, onTap: (index) { setState(() { currentIndex = index; pageController.jumpToPage(index); }); }, ), body: _getPageBody(context), ); } _getPageBody(BuildContext context) { return PageView( controller: pageController, physics: const NeverScrollableScrollPhysics(), onPageChanged: (index) { setState(() { currentIndex = index; }); }, children: pages, ); } }