import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import '../../../core/router/routes.dart'; import '../../../core/constants/app_colors.dart'; import '../../providers/user_providers.dart'; class SplashPage extends ConsumerStatefulWidget { const SplashPage({super.key}); @override ConsumerState createState() => _SplashPageState(); } class _SplashPageState extends ConsumerState { @override void initState() { super.initState(); _initialize(); } Future _initialize() async { await Future.delayed(const Duration(seconds: 2)); if (!mounted) return; // 检查用户登录状态 final userState = ref.read(userNotifierProvider); if (userState.isLoggedIn) { // 已登录,尝试刷新token try { await ref.read(userNotifierProvider.notifier).refreshTokenIfNeeded(); if (mounted) { context.go(Routes.home); } } catch (e) { // token刷新失败,跳转到登录页 if (mounted) { context.go(Routes.login); } } } else { // 未登录,跳转到登录页 context.go(Routes.login); } } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: AppColors.primary, body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Container( width: 100, height: 100, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(20), ), child: const Icon( Icons.eco, size: 60, color: AppColors.primary, ), ), const SizedBox(height: 24), const Text( '榴莲挖矿', style: TextStyle( color: Colors.white, fontSize: 28, fontWeight: FontWeight.bold, ), ), const SizedBox(height: 8), const Text( '绿色财富 共享未来', style: TextStyle( color: Colors.white70, fontSize: 16, ), ), const SizedBox(height: 48), const CircularProgressIndicator( color: Colors.white, strokeWidth: 2, ), ], ), ), ); } }