| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- 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<GoRoute> 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()));
- }
- }
|