main_page.dart 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import 'package:cs_resources/theme/app_colors_theme.dart';
  2. import 'package:flutter/src/widgets/framework.dart';
  3. import 'package:hooks_riverpod/hooks_riverpod.dart';
  4. import 'package:auto_route/auto_route.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:shared/utils/device_utils.dart';
  7. import '../../router/page/main_page_router.dart';
  8. import 'package:router/ext/auto_router_extensions.dart';
  9. import 'main_view_model.dart';
  10. @RoutePage()
  11. class MainPage extends HookConsumerWidget {
  12. const MainPage({super.key});
  13. //启动当前页面
  14. static void startInstance({BuildContext? context}) {
  15. if (context != null) {
  16. context.router.popUntilRoot();
  17. context.router.replace(const MainPageRoute());
  18. } else {
  19. appRouter.popUntilRoot();
  20. appRouter.replace(const MainPageRoute());
  21. }
  22. }
  23. @override
  24. Widget build(BuildContext context, WidgetRef ref) {
  25. final viewModel = ref.watch(mainViewModelProvider.notifier);
  26. final state = ref.watch(mainViewModelProvider);
  27. // return AutoTabsRouter(
  28. // routes: const [
  29. // HomePageRoute(),
  30. // VisitorPageRoute(),
  31. // FeedbackPageRoute(),
  32. // MePageRoute(),
  33. // ],
  34. // transitionBuilder: (context, child, animation) => FadeTransition(
  35. // opacity: animation,
  36. // child: child,
  37. // ),
  38. // builder: (context, child) {
  39. // final tabsRouter = AutoTabsRouter.of(context);
  40. // return AnnotatedRegion<SystemUiOverlayStyle>(
  41. // value: ThemeConfig.getSystemUiOverlayStyleByTheme(context),
  42. // child: Scaffold(
  43. // body: child,
  44. // bottomNavigationBar: BottomNavigationBar(
  45. // backgroundColor: context.theme.primaryColor,
  46. // selectedItemColor: context.theme.colorScheme.secondary,
  47. // unselectedItemColor: Colors.grey[500],
  48. // elevation: 20,
  49. // type: BottomNavigationBarType.fixed,
  50. // items: const <BottomNavigationBarItem>[
  51. // BottomNavigationBarItem(
  52. // icon: Icon(Icons.home),
  53. // label: 'Home',
  54. // ),
  55. // BottomNavigationBarItem(
  56. // icon: Icon(Icons.card_giftcard),
  57. // label: 'Visitor',
  58. // ),
  59. // BottomNavigationBarItem(
  60. // icon: Icon(Icons.feed),
  61. // label: 'Feedback',
  62. // ),
  63. // BottomNavigationBarItem(
  64. // icon: Icon(Icons.person),
  65. // label: 'Me',
  66. // ),
  67. // ],
  68. // onTap: tabsRouter.setActiveIndex,
  69. // currentIndex: tabsRouter.activeIndex,
  70. // ),
  71. // ));
  72. // },
  73. // );
  74. return AutoTabsScaffold(
  75. routes: const [
  76. HomePageRoute(),
  77. VisitorPageRoute(),
  78. FeedbackPageRoute(),
  79. MePageRoute(),
  80. ],
  81. transitionBuilder: (context, child, animation) => FadeTransition(
  82. opacity: animation,
  83. child: child,
  84. ),
  85. bottomNavigationBuilder: (context, tabsRouter) {
  86. return BottomNavigationBar(
  87. elevation: 10,
  88. backgroundColor: context.appColors.whiteBG,
  89. type: BottomNavigationBarType.fixed,
  90. currentIndex: tabsRouter.activeIndex,
  91. onTap: tabsRouter.setActiveIndex,
  92. unselectedLabelStyle: const TextStyle(color: AppColorsTheme.color666666, fontWeight: FontWeight.w400),
  93. selectedLabelStyle: TextStyle(color: context.appColors.textPrimary, fontWeight: FontWeight.w400),
  94. unselectedFontSize: 12,
  95. selectedFontSize: 12,
  96. items: () {
  97. var items = <BottomNavigationBarItem>[];
  98. state.bottomMap.forEach((k, v) {
  99. items.add(BottomNavigationBarItem(
  100. label: k,
  101. icon: v[0],
  102. activeIcon: DeviceUtils.isDarkMode(context) ? v[2] : v[1],
  103. ));
  104. });
  105. return items;
  106. }(),
  107. );
  108. },
  109. );
  110. }
  111. }