view.dart 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import 'package:electronic_assistant/base/base_page.dart';
  2. import 'package:electronic_assistant/module/main/controller.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:get/get.dart';
  5. class MainTabPage extends BasePage<MainController> {
  6. const MainTabPage({super.key});
  7. @override
  8. Widget? buildBody(BuildContext context) {
  9. return Scaffold(
  10. body: const Center(
  11. child: Text('MainTabPage'),
  12. ),
  13. bottomNavigationBar: BottomAppBar(
  14. color: Colors.white,
  15. height: 68,
  16. shape: const CircularNotchedRectangle(),
  17. child: Obx(() {
  18. return Row(
  19. mainAxisAlignment: MainAxisAlignment.spaceAround,
  20. children: <Widget>[
  21. SizedBox(child: bottomAppBarItem(0)),
  22. const SizedBox(),
  23. SizedBox(child: bottomAppBarItem(1)),
  24. ],
  25. );
  26. }),
  27. ),
  28. drawer: Drawer(
  29. child: Center(
  30. child: Column(
  31. mainAxisAlignment: MainAxisAlignment.center,
  32. children: <Widget>[
  33. const Text('This is the Drawer'),
  34. ElevatedButton(
  35. onPressed: () {},
  36. child: const Text('Close Drawer'),
  37. ),
  38. ],
  39. ),
  40. ),
  41. ),
  42. );
  43. }
  44. Widget bottomAppBarItem(int index) {
  45. //设置默认未选中的状态
  46. TextStyle style;
  47. TabBean tabBean = controller.tabBeans[index];
  48. String imagePath;
  49. if (controller.currentIndex == index) {
  50. //选中的话
  51. style = TextStyle(fontSize: 10, color: tabBean.txtSelectedColor);
  52. imagePath = tabBean.selectedIcon;
  53. } else {
  54. style = TextStyle(fontSize: 10, color: tabBean.txtNormalColor);
  55. imagePath = tabBean.normalIcon;
  56. }
  57. //构造返回的Widget
  58. Widget item = GestureDetector(
  59. behavior: HitTestBehavior.opaque,
  60. child: Center(
  61. child: Column(
  62. mainAxisSize: MainAxisSize.min,
  63. children: <Widget>[
  64. Image.asset(imagePath, width: 24, height: 24),
  65. Text(
  66. tabBean.title,
  67. style: style,
  68. )
  69. ],
  70. ),
  71. ),
  72. onTap: () {
  73. if (controller.currentIndex != index) {
  74. controller.updateIndex(index);
  75. }
  76. },
  77. );
  78. return item;
  79. }
  80. // List<BottomNavigationBarItem> get _buildBottomBarItem {
  81. // return [
  82. // BottomNavigationBarItem(
  83. // icon: Assets.images.mainTabHomeUnSelect.image(width: 24, height: 24),
  84. // activeIcon:
  85. // Assets.images.mainTabHomeSelected.image(width: 24, height: 24),
  86. // label: 'main_tab_home'.tr,
  87. // ),
  88. // const BottomNavigationBarItem(
  89. // icon: SizedBox(width: 24, height: 24),
  90. // label: '',
  91. // ),
  92. // BottomNavigationBarItem(
  93. // icon: Assets.images.mainTabFileUnSelect.image(width: 24, height: 24),
  94. // activeIcon:
  95. // Assets.images.mainTabFileSelected.image(width: 24, height: 24),
  96. // label: 'main_tab_file'.tr,
  97. // ),
  98. // ];
  99. // }
  100. }