app_routes.dart 6.3 KB

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