app_routes.dart 5.3 KB

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