main_page.dart 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import 'package:flutter/src/widgets/framework.dart';
  2. import 'package:hooks_riverpod/hooks_riverpod.dart';
  3. import 'package:auto_route/auto_route.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:shared/utils/ext_dart.dart';
  6. import '../../../router/page/main_page_router.dart';
  7. import 'package:router/ext/auto_router_extensions.dart';
  8. @RoutePage()
  9. class MainPage extends HookConsumerWidget {
  10. const MainPage({super.key});
  11. //启动当前页面
  12. static void startInstance({BuildContext? context}) {
  13. if (context != null) {
  14. context.router.popUntilRoot();
  15. context.router.replace(const MainPageRoute());
  16. } else {
  17. appRouter.popUntilRoot();
  18. appRouter.replace(const MainPageRoute());
  19. }
  20. }
  21. @override
  22. Widget build(BuildContext context, WidgetRef ref) {
  23. return AutoTabsScaffold(
  24. routes: const [
  25. HomePageRoute(),
  26. VisitorPageRoute(),
  27. FeedbackPageRoute(),
  28. MePageRoute(),
  29. ],
  30. transitionBuilder: (context, child, animation) => FadeTransition(
  31. opacity: animation,
  32. child: child,
  33. ),
  34. bottomNavigationBuilder: (context, tabsRouter) {
  35. return BottomNavigationBar(
  36. unselectedItemColor: Colors.grey[500],
  37. elevation: 20,
  38. type: BottomNavigationBarType.fixed,
  39. currentIndex: tabsRouter.activeIndex,
  40. onTap: tabsRouter.setActiveIndex,
  41. items: const [
  42. BottomNavigationBarItem(
  43. icon: Icon(Icons.home),
  44. label: 'Home',
  45. ),
  46. BottomNavigationBarItem(
  47. icon: Icon(Icons.card_giftcard),
  48. label: 'Visitor',
  49. ),
  50. BottomNavigationBarItem(
  51. icon: Icon(Icons.feed),
  52. label: 'Feedback',
  53. ),
  54. BottomNavigationBarItem(
  55. icon: Icon(Icons.person),
  56. label: 'Me',
  57. ),
  58. ],
  59. );
  60. },
  61. );
  62. }
  63. }