app_routes.dart 5.0 KB

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