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.dart'; import '../pages/home/home.dart'; import '../pages/checkin/checkin_page.dart'; import '../pages/sample_transfer/sample_transfer_page.dart'; class AppRoutePaths { static const String splash = '/'; static const String login = '/login'; static const String home = '/home'; static const String checkin = '/checkin'; static const String sampleTransfer = '/sample_transfer'; } class AppRoutes { static final List routes = [ GoRoute( path: AppRoutePaths.splash, builder: (context, state) => const SplashScreen(), ), GoRoute( path: AppRoutePaths.login, name: AppRoutePaths.login, builder: (context, state) => const LoginPage(), ), GoRoute( path: AppRoutePaths.home, name: AppRoutePaths.home, builder: (context, state) => const HomePage(), ), GoRoute( path: AppRoutePaths.checkin, name: AppRoutePaths.checkin, builder: (context, state) => const CheckinPage(), ), GoRoute( path: AppRoutePaths.sampleTransfer, name: AppRoutePaths.sampleTransfer, builder: (context, state) => const SampleTransferPage(), ), ]; } // 启动屏 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(AppRoutePaths.home); } else if (next.state != AuthState.loading) { context.goNamed(AppRoutePaths.login); } }); return const Scaffold(body: Center(child: CircularProgressIndicator())); } }