main_page.dart 2.6 KB

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