view.dart 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import 'package:electronic_assistant/base/base_page.dart';
  2. import 'package:electronic_assistant/main.dart';
  3. import 'package:electronic_assistant/module/main/controller.dart';
  4. import 'package:electronic_assistant/resource/assets.gen.dart';
  5. import 'package:electronic_assistant/resource/colors.gen.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:flutter_screenutil/flutter_screenutil.dart';
  8. import 'package:get/get.dart';
  9. import '../files/view.dart';
  10. import '../home/view.dart';
  11. class MainTabPage extends BasePage<MainController> {
  12. MainTabPage({super.key});
  13. final pages = [
  14. HomePage(),
  15. const FilesPage(),
  16. ];
  17. @override
  18. Widget buildBody(BuildContext context) {
  19. return Scaffold(
  20. body: Obx(() {
  21. return pages[controller.currentIndex];
  22. }),
  23. floatingActionButton: buildAIChatBtn(),
  24. floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
  25. bottomNavigationBar: buildBottomAppBar(),
  26. drawer: Drawer(
  27. child: Center(
  28. child: Column(
  29. mainAxisAlignment: MainAxisAlignment.center,
  30. children: <Widget>[
  31. const Text('This is the Drawer'),
  32. ElevatedButton(
  33. onPressed: () {},
  34. child: const Text('Close Drawer'),
  35. ),
  36. ],
  37. ),
  38. ),
  39. ),
  40. );
  41. }
  42. Container buildAIChatBtn() {
  43. return Container(
  44. width: 68.w,
  45. height: 68.w,
  46. decoration: const BoxDecoration(
  47. color: ColorName.white,
  48. shape: BoxShape.circle,
  49. ),
  50. margin: EdgeInsets.only(top: 36.w),
  51. padding: EdgeInsets.all(6.w),
  52. child: Assets.images.mainTabSecretary.image(),
  53. );
  54. }
  55. BottomAppBar buildBottomAppBar() {
  56. return BottomAppBar(
  57. color: Colors.white,
  58. height: 68.h,
  59. child: Obx(() {
  60. return Flex(
  61. mainAxisAlignment: MainAxisAlignment.spaceAround,
  62. direction: Axis.horizontal,
  63. children: <Widget>[
  64. Expanded(
  65. flex: 1,
  66. child: bottomAppBarItem(0),
  67. ),
  68. const Expanded(
  69. flex: 1,
  70. child: SizedBox(),
  71. ),
  72. const SizedBox(),
  73. Expanded(
  74. flex: 1,
  75. child: bottomAppBarItem(1),
  76. ),
  77. ],
  78. );
  79. }),
  80. );
  81. }
  82. Widget bottomAppBarItem(int index) {
  83. //设置默认未选中的状态
  84. TextStyle style;
  85. TabBean tabBean = controller.tabBeans[index];
  86. String imagePath;
  87. if (controller.currentIndex == index) {
  88. //选中的话
  89. style = TextStyle(fontSize: 10.sp, color: tabBean.txtSelectedColor);
  90. imagePath = tabBean.selectedIcon;
  91. } else {
  92. style = TextStyle(fontSize: 10.sp, color: tabBean.txtNormalColor);
  93. imagePath = tabBean.normalIcon;
  94. }
  95. //构造返回的Widget
  96. Widget item = GestureDetector(
  97. behavior: HitTestBehavior.opaque,
  98. child: Center(
  99. child: Column(
  100. mainAxisSize: MainAxisSize.min,
  101. children: <Widget>[
  102. Image.asset(imagePath, width: 24.w, height: 24.w),
  103. Text(
  104. tabBean.title.tr,
  105. style: style,
  106. )
  107. ],
  108. ),
  109. ),
  110. onTap: () {
  111. if (controller.currentIndex != index) {
  112. controller.updateIndex(index);
  113. }
  114. },
  115. );
  116. return item;
  117. }
  118. }