app_routes.dart 6.0 KB

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