app_routes.dart 5.7 KB

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