163 lines
4.5 KiB
Dart
163 lines
4.5 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||
import 'package:go_router/go_router.dart';
|
||
import '../../../../core/constants/app_constants.dart';
|
||
import '../../../../routes/route_paths.dart';
|
||
import '../../../../bootstrap.dart';
|
||
import '../providers/auth_provider.dart';
|
||
|
||
/// 开屏页面 - 应用启动时显示的第一个页面
|
||
/// 显示 Logo 和应用名称,同时检查用户认证状态
|
||
class SplashPage extends ConsumerStatefulWidget {
|
||
const SplashPage({super.key});
|
||
|
||
@override
|
||
ConsumerState<SplashPage> createState() => _SplashPageState();
|
||
}
|
||
|
||
class _SplashPageState extends ConsumerState<SplashPage> {
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
_initializeApp();
|
||
}
|
||
|
||
/// 初始化应用并检查认证状态
|
||
Future<void> _initializeApp() async {
|
||
// 初始化遥测服务(需要 BuildContext)
|
||
await initializeTelemetry(context);
|
||
|
||
// 等待开屏动画展示
|
||
await Future.delayed(AppConstants.splashDuration);
|
||
|
||
// 检查认证状态
|
||
await ref.read(authProvider.notifier).checkAuthStatus();
|
||
|
||
if (!mounted) return;
|
||
|
||
final authState = ref.read(authProvider);
|
||
|
||
// 根据认证状态决定跳转目标
|
||
String targetRoute;
|
||
if (authState.isWalletCreated) {
|
||
// 已创建钱包,进入主页面(龙虎榜)
|
||
targetRoute = RoutePaths.ranking;
|
||
} else if (authState.isFirstLaunch || !authState.hasSeenGuide) {
|
||
// 首次打开或未看过向导,进入向导页
|
||
targetRoute = RoutePaths.guide;
|
||
} else {
|
||
// 已看过向导但未创建钱包,直接进入创建账户页面
|
||
targetRoute = RoutePaths.onboarding;
|
||
}
|
||
|
||
// 跳转到目标页面
|
||
context.go(targetRoute);
|
||
|
||
// 延迟检查应用更新(跳转后执行,避免阻塞启动)
|
||
if (targetRoute == RoutePaths.ranking) {
|
||
// 只在进入主页面时检查更新
|
||
checkForAppUpdate(context);
|
||
}
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Scaffold(
|
||
body: Container(
|
||
width: double.infinity,
|
||
height: double.infinity,
|
||
// 渐变背景 - 从浅米色到金黄色
|
||
decoration: const BoxDecoration(
|
||
gradient: LinearGradient(
|
||
begin: Alignment.topCenter,
|
||
end: Alignment.bottomCenter,
|
||
colors: [
|
||
Color(0xFFFFF5E6), // 浅米色
|
||
Color(0xFFFFE4B5), // 金黄色
|
||
],
|
||
),
|
||
),
|
||
child: Column(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
children: [
|
||
// Logo 图片容器
|
||
_buildLogo(),
|
||
const SizedBox(height: 24),
|
||
// 应用名称
|
||
_buildAppTitle(),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
/// 构建 Logo 组件
|
||
/// 深色背景上的皇冠图标
|
||
Widget _buildLogo() {
|
||
return Container(
|
||
width: 128,
|
||
height: 152,
|
||
decoration: BoxDecoration(
|
||
color: const Color(0xFF2D2A26), // 深棕色背景
|
||
borderRadius: BorderRadius.circular(8),
|
||
),
|
||
child: Column(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
children: [
|
||
// 皇冠图标
|
||
Container(
|
||
width: 64,
|
||
height: 48,
|
||
decoration: BoxDecoration(
|
||
color: const Color(0xFFD4A84B), // 金色
|
||
borderRadius: BorderRadius.circular(8),
|
||
),
|
||
child: const Icon(
|
||
Icons.workspace_premium,
|
||
size: 32,
|
||
color: Color(0xFF2D2A26),
|
||
),
|
||
),
|
||
const SizedBox(height: 16),
|
||
// DURIAN 文字
|
||
const Text(
|
||
'DURIAN',
|
||
style: TextStyle(
|
||
fontSize: 12,
|
||
fontWeight: FontWeight.w600,
|
||
letterSpacing: 2,
|
||
color: Color(0xFFD4A84B),
|
||
),
|
||
),
|
||
const SizedBox(height: 2),
|
||
// QUEEN 文字
|
||
const Text(
|
||
'QUEEN',
|
||
style: TextStyle(
|
||
fontSize: 10,
|
||
fontWeight: FontWeight.w400,
|
||
letterSpacing: 1.5,
|
||
color: Color(0xFFD4A84B),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
/// 构建应用标题
|
||
Widget _buildAppTitle() {
|
||
return const Text(
|
||
'榴莲女皇',
|
||
style: TextStyle(
|
||
fontSize: 32,
|
||
fontFamily: 'Noto Sans SC',
|
||
fontWeight: FontWeight.w700,
|
||
height: 1.25,
|
||
letterSpacing: 1.6,
|
||
color: Color(0xFF4A3F35), // 深棕色文字
|
||
),
|
||
);
|
||
}
|
||
}
|