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'; class AppRoutePaths { static const String splash = '/'; static const String login = '/login'; static const String home = '/home'; } 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(), ), ]; } // 启动屏 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())); } }