index_page.dart 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import 'package:flutter/material.dart';
  2. import 'package:gobang/pages/home_page.dart';
  3. import 'package:gobang/pages/mine_page.dart';
  4. /// Description: index page
  5. /// Time : 02/21/2024 Wednesday
  6. /// Author : liuyuqi.gov@msn.cn
  7. class IndexPage extends StatefulWidget {
  8. const IndexPage({Key? key}) : super(key: key);
  9. @override
  10. State<IndexPage> createState() => _IndexPageState();
  11. }
  12. class _IndexPageState extends State<IndexPage> {
  13. final List<BottomNavigationBarItem> bottomTabs = const [
  14. BottomNavigationBarItem(icon: Icon(Icons.home), label: '出行'),
  15. BottomNavigationBarItem(icon: Icon(Icons.business), label: '大厅'),
  16. BottomNavigationBarItem(icon: Icon(Icons.school), label: '消息'),
  17. BottomNavigationBarItem(icon: Icon(Icons.school), label: '我的'),
  18. ];
  19. final List<Widget> pages = [
  20. HomePage(),
  21. MinePage(),
  22. ];
  23. int currentIndex = 0;
  24. Size get size => MediaQuery.of(context).size;
  25. final pageController = PageController();
  26. @override
  27. Widget build(BuildContext context) {
  28. return Scaffold(
  29. appBar: AppBar(
  30. actions: [Icon(Icons.search)],
  31. title: Text("gobang"),
  32. ),
  33. // drawer: ,
  34. bottomNavigationBar: BottomNavigationBar(
  35. items: bottomTabs,
  36. currentIndex: currentIndex,
  37. type: BottomNavigationBarType.fixed,
  38. onTap: (index) {
  39. setState(() {
  40. currentIndex = index;
  41. pageController.jumpToPage(index);
  42. });
  43. },
  44. ),
  45. body: _getPageBody(context),
  46. );
  47. }
  48. _getPageBody(BuildContext context) {
  49. return PageView(
  50. controller: pageController,
  51. physics: const NeverScrollableScrollPhysics(),
  52. onPageChanged: (index) {
  53. setState(() {
  54. currentIndex = index;
  55. });
  56. },
  57. children: pages,
  58. );
  59. }
  60. }