app_routes.dart 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import 'package:chicken_farm/pages/dict/dict_manage_page.dart';
  2. import 'package:chicken_farm/stores/auth_store.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_riverpod/flutter_riverpod.dart';
  5. import 'package:go_router/go_router.dart';
  6. import '../pages/account/login_page.dart';
  7. import '../pages/home/home_page.dart';
  8. import '../pages/home/_profile/rfid_config_page.dart';
  9. import '../pages/checkin/checkin_page.dart';
  10. import '../pages/checkin/checkin_record_page.dart';
  11. import '../pages/sample/sample_query_page.dart';
  12. import '../pages/sample/sample_detail_page.dart';
  13. import '../pages/breeding/batch_create_page.dart';
  14. import '../pages/breeding/batch_create_page_win.dart';
  15. import '../pages/breeding/cage_change_page.dart';
  16. import '../pages/breeding/individual_weighing_page.dart';
  17. import '../pages/breeding/individual_culling_page.dart';
  18. import '../pages/breeding/batch_culling_page.dart';
  19. import '../pages/breeding/batch_culling_page_win.dart';
  20. import '../pages/upload/upload_page.dart';
  21. class AppRouteNames {
  22. static const String splash = '/';
  23. static const String login = '/login';
  24. static const String home = '/home';
  25. static const String checkin = '/checkin';
  26. static const String checkinRecord = '/checkin_record';
  27. static const String bindChicken = '/bind_chicken';
  28. static const String bindwingTagNumWin =
  29. '/bind_wing_tag_num_win'; // Windows平台个体绑定
  30. static const String cageChange = '/cage_change';
  31. static const String individualWeighing = '/individual_weighing';
  32. static const String individualCulling = '/individual_culling';
  33. static const String batchCulling = '/batch_culling';
  34. static const String batchCullingWin = '/batch_culling_win'; // Windows平台批量淘汰
  35. static const String sample = '/sample';
  36. static const String sampleDetail = '/sample/detail';
  37. static const String rfidConfig = '/rfid-config';
  38. static const String upload = '/upload';
  39. static const String dictManage = '/dict_manage';
  40. }
  41. class AppRoutes {
  42. static final List<GoRoute> routes = [
  43. GoRoute(
  44. path: AppRouteNames.splash,
  45. builder: (context, state) => const SplashScreen(),
  46. ),
  47. GoRoute(
  48. path: AppRouteNames.login,
  49. name: AppRouteNames.login,
  50. builder: (context, state) => const LoginPage(),
  51. ),
  52. GoRoute(
  53. path: AppRouteNames.home,
  54. name: AppRouteNames.home,
  55. builder: (context, state) => const HomePage(),
  56. ),
  57. GoRoute(
  58. path: AppRouteNames.checkin,
  59. name: AppRouteNames.checkin,
  60. builder: (context, state) => const CheckinPage(),
  61. ),
  62. GoRoute(
  63. path: '${AppRouteNames.checkinRecord}/:id',
  64. name: AppRouteNames.checkinRecord,
  65. builder: (context, state) {
  66. final id = state.pathParameters['id'] ?? '';
  67. return CheckinRecordPage(id: id);
  68. },
  69. ),
  70. GoRoute(
  71. path: AppRouteNames.sample,
  72. name: AppRouteNames.sample,
  73. builder: (context, state) => const SampleQueryPage(),
  74. ),
  75. GoRoute(
  76. path: '${AppRouteNames.sampleDetail}/:id',
  77. name: AppRouteNames.sampleDetail,
  78. builder: (context, state) {
  79. final id = state.pathParameters['id'] ?? '';
  80. return SampleDetailPage(id: id);
  81. },
  82. ),
  83. GoRoute(
  84. path: AppRouteNames.bindChicken,
  85. name: AppRouteNames.bindChicken,
  86. builder: (context, state) => const BatchCreatePage(),
  87. ),
  88. GoRoute(
  89. path: AppRouteNames.cageChange,
  90. name: AppRouteNames.cageChange,
  91. builder: (context, state) => const CageChangePage(),
  92. ),
  93. GoRoute(
  94. path: AppRouteNames.individualWeighing,
  95. name: AppRouteNames.individualWeighing,
  96. builder: (context, state) => const IndividualWeighingPage(),
  97. ),
  98. GoRoute(
  99. path: AppRouteNames.individualCulling,
  100. name: AppRouteNames.individualCulling,
  101. builder: (context, state) => const IndividualCullingPage(),
  102. ),
  103. GoRoute(
  104. path: AppRouteNames.batchCulling,
  105. name: AppRouteNames.batchCulling,
  106. builder: (context, state) => const BatchCullingPage(),
  107. ),
  108. GoRoute(
  109. path: AppRouteNames.bindwingTagNumWin,
  110. name: AppRouteNames.bindwingTagNumWin,
  111. builder: (context, state) => const BatchCreatePageWin(),
  112. ),
  113. GoRoute(
  114. path: AppRouteNames.batchCullingWin,
  115. name: AppRouteNames.batchCullingWin,
  116. builder: (context, state) => const BatchCullingPageWin(),
  117. ),
  118. GoRoute(
  119. path: AppRouteNames.rfidConfig,
  120. name: AppRouteNames.rfidConfig,
  121. builder: (context, state) => const RfidConfigPage(),
  122. ),
  123. GoRoute(
  124. path: AppRouteNames.upload,
  125. name: AppRouteNames.upload,
  126. builder: (context, state) => const UploadPage(),
  127. ),
  128. GoRoute(
  129. path: AppRouteNames.dictManage,
  130. name: AppRouteNames.dictManage,
  131. builder: (context, state) => const DictManagePage(),
  132. ),
  133. ];
  134. }
  135. // 启动屏
  136. class SplashScreen extends ConsumerWidget {
  137. const SplashScreen({super.key});
  138. @override
  139. Widget build(BuildContext context, WidgetRef ref) {
  140. ref.listen(authStoreProvider, (previous, next) {
  141. if (next.state == AuthState.authenticated) {
  142. WidgetsBinding.instance.addPostFrameCallback((_) {
  143. if (context.mounted) {
  144. context.goNamed(AppRouteNames.home);
  145. }
  146. });
  147. } else if (next.state != AuthState.loading) {
  148. WidgetsBinding.instance.addPostFrameCallback((_) {
  149. if (context.mounted) {
  150. context.goNamed(AppRouteNames.login);
  151. }
  152. });
  153. }
  154. });
  155. return const Scaffold(body: Center(child: CircularProgressIndicator()));
  156. }
  157. }