import 'package:chicken_farm/stores/auth_store.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import '../pages/account/login_page.dart'; import '../pages/home/home_page.dart'; import '../pages/home/_profile/rfid_config_page.dart'; import '../pages/checkin/checkin_page.dart'; import '../pages/checkin/checkin_record_page.dart'; import '../pages/sample/sample_query_page.dart'; import '../pages/sample/sample_detail_page.dart'; import '../pages/breeding/batch_create_page.dart'; import '../pages/breeding/cage_change_page.dart'; import '../pages/breeding/individual_weighing_page.dart'; import '../pages/breeding/individual_culling_page.dart'; import '../pages/breeding/batch_culling_page.dart'; import '../pages/upload/upload_page.dart'; class AppRouteNames { static const String splash = '/'; static const String login = '/login'; static const String home = '/home'; static const String checkin = '/checkin'; static const String checkinRecord = '/checkin_record'; static const String bindwingTagNum = '/bind_wing_tag_num'; static const String cageChange = '/cage_change'; static const String individualWeighing = '/individual_weighing'; static const String individualCulling = '/individual_culling'; static const String batchCulling = '/batch_culling'; static const String sample = '/sample'; static const String sampleDetail = '/sample/detail'; static const String rfidConfig = '/rfid-config'; static const String upload = '/upload'; // 新增上传路由名称 } class AppRoutes { static final List routes = [ GoRoute( path: AppRouteNames.splash, builder: (context, state) => const SplashScreen(), ), GoRoute( path: AppRouteNames.login, name: AppRouteNames.login, builder: (context, state) => const LoginPage(), ), GoRoute( path: AppRouteNames.home, name: AppRouteNames.home, builder: (context, state) => const HomePage(), ), GoRoute( path: AppRouteNames.checkin, name: AppRouteNames.checkin, builder: (context, state) => const CheckinPage(), ), GoRoute( path: '${AppRouteNames.checkinRecord}/:id', name: AppRouteNames.checkinRecord, builder: (context, state) { final id = state.pathParameters['id'] ?? ''; return CheckinRecordPage(id: id); }, ), GoRoute( path: AppRouteNames.sample, name: AppRouteNames.sample, builder: (context, state) => const SampleQueryPage(), ), GoRoute( path: '${AppRouteNames.sampleDetail}/:id', name: AppRouteNames.sampleDetail, builder: (context, state) { final id = state.pathParameters['id'] ?? ''; return SampleDetailPage(id: id); }, ), GoRoute( path: AppRouteNames.bindwingTagNum, name: AppRouteNames.bindwingTagNum, builder: (context, state) => const BatchCreatePage(), ), GoRoute( path: AppRouteNames.cageChange, name: AppRouteNames.cageChange, builder: (context, state) => const CageChangePage(), ), GoRoute( path: AppRouteNames.individualWeighing, name: AppRouteNames.individualWeighing, builder: (context, state) => const IndividualWeighingPage(), ), GoRoute( path: AppRouteNames.individualCulling, name: AppRouteNames.individualCulling, builder: (context, state) => const IndividualCullingPage(), ), GoRoute( path: AppRouteNames.batchCulling, name: AppRouteNames.batchCulling, builder: (context, state) => const BatchCullingPage(), ), GoRoute( path: AppRouteNames.rfidConfig, name: AppRouteNames.rfidConfig, builder: (context, state) => const RfidConfigPage(), ), // 新增上传路由 GoRoute( path: AppRouteNames.upload, name: AppRouteNames.upload, builder: (context, state) => const UploadPage(), ), ]; } // 启动屏 class SplashScreen extends ConsumerWidget { const SplashScreen({super.key}); @override Widget build(BuildContext context, WidgetRef ref) { ref.listen(authStoreProvider, (previous, next) { if (next.state == AuthState.authenticated) { context.goNamed(AppRouteNames.home); } else if (next.state != AuthState.loading) { context.goNamed(AppRouteNames.login); } }); return const Scaffold(body: Center(child: CircularProgressIndicator())); } }