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/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/bind_wing_tag_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 sample = '/sample'; static const String sampleDetail = '/sample/detail'; } 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 BindWingTagNumPage(), ), ]; } // 启动屏 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())); } }