main_page.dart 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:get/get.dart';
  4. import '../../base/base_page.dart';
  5. import '../../router/app_pages.dart';
  6. import 'main_controller.dart';
  7. class MainPage extends BasePage<MainController> {
  8. MainPage({super.key});
  9. static start({Map<String, dynamic>? arguments}) {
  10. return Get.offAllNamed(RoutePath.mainTab, arguments: arguments);
  11. }
  12. @override
  13. bool immersive() => true;
  14. @override
  15. Widget buildBody(BuildContext context) {
  16. return PopScope(
  17. child: Scaffold(
  18. bottomNavigationBar: buildBottomAppBar(),
  19. drawerEdgeDragWidth: 0,
  20. body: Obx(() => controller.tabBeans[controller.currentIndex].page),
  21. ),
  22. );
  23. }
  24. Widget buildBottomAppBar() {
  25. return Container(
  26. decoration: BoxDecoration(color: Colors.white),
  27. child: BottomAppBar(
  28. color: Colors.white,
  29. height: 56.h,
  30. padding: EdgeInsets.zero,
  31. child: Row(
  32. mainAxisAlignment: MainAxisAlignment.spaceAround,
  33. children: List.generate(controller.tabBeans.length, bottomAppBarItem),
  34. ),
  35. ),
  36. );
  37. }
  38. Widget bottomAppBarItem(int index) {
  39. return Obx(() {
  40. TabBean tabBean = controller.tabBeans[index];
  41. bool isSelected = controller.currentIndex == index;
  42. TextStyle style = TextStyle(
  43. fontSize: 10.sp,
  44. fontWeight: FontWeight.w400,
  45. color:
  46. isSelected
  47. ? const Color(0xFF7D46FC)
  48. : Colors.black.withValues(alpha: 0.4),
  49. );
  50. String imagePath = isSelected ? tabBean.selectedIcon : tabBean.normalIcon;
  51. return GestureDetector(
  52. behavior: HitTestBehavior.opaque,
  53. onTap: () {
  54. controller.changeIndex(index);
  55. },
  56. child: SizedBox(
  57. height: 56.h,
  58. child: Column(
  59. mainAxisAlignment: MainAxisAlignment.center,
  60. children: [
  61. Image.asset(imagePath, width: 28.w, height: 28.w),
  62. Text(tabBean.title, style: style),
  63. ],
  64. ),
  65. ),
  66. );
  67. });
  68. }
  69. }