view.dart 3.4 KB

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