app_routes.dart 4.4 KB

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