app_routes.dart 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import 'package:chicken_farm/stores/auth_store.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_riverpod/flutter_riverpod.dart';
  4. import 'package:go_router/go_router.dart';
  5. import '../pages/account/login_page.dart';
  6. import '../pages/home/home_page.dart';
  7. import '../pages/home/_profile/rfid_config_page.dart';
  8. import '../pages/checkin/checkin_page.dart';
  9. import '../pages/checkin/checkin_record_page.dart';
  10. import '../pages/sample/sample_query_page.dart';
  11. import '../pages/sample/sample_detail_page.dart';
  12. import '../pages/breeding/batch_create_page.dart';
  13. import '../pages/breeding/cage_change_page.dart';
  14. import '../pages/breeding/individual_weighing_page.dart';
  15. import '../pages/breeding/individual_culling_page.dart';
  16. import '../pages/breeding/batch_culling_page.dart';
  17. class AppRouteNames {
  18. static const String splash = '/';
  19. static const String login = '/login';
  20. static const String home = '/home';
  21. static const String checkin = '/checkin';
  22. static const String checkinRecord = '/checkin_record';
  23. static const String bindwingTagNum = '/bind_wing_tag_num';
  24. static const String cageChange = '/cage_change';
  25. static const String individualWeighing = '/individual_weighing';
  26. static const String individualCulling = '/individual_culling';
  27. static const String batchCulling = '/batch_culling';
  28. static const String sample = '/sample';
  29. static const String sampleDetail = '/sample/detail';
  30. static const String rfidConfig = '/rfid-config';
  31. }
  32. class AppRoutes {
  33. static final List<GoRoute> routes = [
  34. GoRoute(
  35. path: AppRouteNames.splash,
  36. builder: (context, state) => const SplashScreen(),
  37. ),
  38. GoRoute(
  39. path: AppRouteNames.login,
  40. name: AppRouteNames.login,
  41. builder: (context, state) => const LoginPage(),
  42. ),
  43. GoRoute(
  44. path: AppRouteNames.home,
  45. name: AppRouteNames.home,
  46. builder: (context, state) => const HomePage(),
  47. ),
  48. GoRoute(
  49. path: AppRouteNames.checkin,
  50. name: AppRouteNames.checkin,
  51. builder: (context, state) => const CheckinPage(),
  52. ),
  53. GoRoute(
  54. path: '${AppRouteNames.checkinRecord}/:id',
  55. name: AppRouteNames.checkinRecord,
  56. builder: (context, state) {
  57. final id = state.pathParameters['id'] ?? '';
  58. return CheckinRecordPage(id: id);
  59. },
  60. ),
  61. GoRoute(
  62. path: AppRouteNames.sample,
  63. name: AppRouteNames.sample,
  64. builder: (context, state) => const SampleQueryPage(),
  65. ),
  66. GoRoute(
  67. path: '${AppRouteNames.sampleDetail}/:id',
  68. name: AppRouteNames.sampleDetail,
  69. builder: (context, state) {
  70. final id = state.pathParameters['id'] ?? '';
  71. return SampleDetailPage(id: id);
  72. },
  73. ),
  74. GoRoute(
  75. path: AppRouteNames.bindwingTagNum,
  76. name: AppRouteNames.bindwingTagNum,
  77. builder: (context, state) => const BatchCreatePage(),
  78. ),
  79. GoRoute(
  80. path: AppRouteNames.cageChange,
  81. name: AppRouteNames.cageChange,
  82. builder: (context, state) => const CageChangePage(),
  83. ),
  84. GoRoute(
  85. path: AppRouteNames.individualWeighing,
  86. name: AppRouteNames.individualWeighing,
  87. builder: (context, state) => const IndividualWeighingPage(),
  88. ),
  89. GoRoute(
  90. path: AppRouteNames.individualCulling,
  91. name: AppRouteNames.individualCulling,
  92. builder: (context, state) => const IndividualCullingPage(),
  93. ),
  94. GoRoute(
  95. path: AppRouteNames.batchCulling,
  96. name: AppRouteNames.batchCulling,
  97. builder: (context, state) => const BatchCullingPage(),
  98. ),
  99. GoRoute(
  100. path: AppRouteNames.rfidConfig,
  101. name: AppRouteNames.rfidConfig,
  102. builder: (context, state) => const RfidConfigPage(),
  103. ),
  104. ];
  105. }
  106. // 启动屏
  107. class SplashScreen extends ConsumerWidget {
  108. const SplashScreen({super.key});
  109. @override
  110. Widget build(BuildContext context, WidgetRef ref) {
  111. ref.listen(authStoreProvider, (previous, next) {
  112. if (next.state == AuthState.authenticated) {
  113. context.goNamed(AppRouteNames.home);
  114. } else if (next.state != AuthState.loading) {
  115. context.goNamed(AppRouteNames.login);
  116. }
  117. });
  118. return const Scaffold(body: Center(child: CircularProgressIndicator()));
  119. }
  120. }