2026-03-25 23:56:23 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:shadcn_ui/shadcn_ui.dart';
|
2026-04-05 23:37:27 +08:00
|
|
|
import '../../../core/theme/app_color_scheme.dart';
|
2026-03-25 23:56:23 +08:00
|
|
|
import '../../../core/theme/app_spacing.dart';
|
2026-04-05 23:37:27 +08:00
|
|
|
import '../../../core/theme/app_theme.dart';
|
2026-04-06 01:58:08 +08:00
|
|
|
import '../../../core/theme/app_theme_extension.dart';
|
2026-03-25 23:56:23 +08:00
|
|
|
import '../../../core/storage/local_storage.dart';
|
|
|
|
|
|
|
|
|
|
/// 引导页数据模型
|
|
|
|
|
class _OnboardingItem {
|
|
|
|
|
final String title;
|
|
|
|
|
final String description;
|
2026-03-26 00:00:27 +08:00
|
|
|
final IconData? icon; // 图标(二选一)
|
|
|
|
|
final String? imagePath; // 图片路径(二选一)
|
2026-03-25 23:56:23 +08:00
|
|
|
final List<Color> gradientColors;
|
|
|
|
|
|
|
|
|
|
const _OnboardingItem({
|
|
|
|
|
required this.title,
|
|
|
|
|
required this.description,
|
2026-03-26 00:00:27 +08:00
|
|
|
this.icon,
|
|
|
|
|
this.imagePath,
|
2026-03-25 23:56:23 +08:00
|
|
|
required this.gradientColors,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// 首次启动引导页
|
|
|
|
|
class OnboardingPage extends StatefulWidget {
|
|
|
|
|
final VoidCallback onComplete;
|
|
|
|
|
|
|
|
|
|
const OnboardingPage({super.key, required this.onComplete});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<OnboardingPage> createState() => _OnboardingPageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _OnboardingPageState extends State<OnboardingPage> {
|
|
|
|
|
final PageController _pageController = PageController();
|
|
|
|
|
int _currentPage = 0;
|
|
|
|
|
|
|
|
|
|
final _items = const [
|
|
|
|
|
_OnboardingItem(
|
|
|
|
|
title: '实时行情',
|
|
|
|
|
description: '全球市场行情实时更新,把握每一个投资机会',
|
2026-03-26 00:00:27 +08:00
|
|
|
imagePath: 'assets/images/onboarding_1.png', // 替换为你的图片
|
2026-04-05 23:37:27 +08:00
|
|
|
gradientColors: [AppColorScheme.darkPrimary, AppColorScheme.darkPrimaryContainer],
|
2026-03-25 23:56:23 +08:00
|
|
|
),
|
|
|
|
|
_OnboardingItem(
|
|
|
|
|
title: '模拟交易',
|
|
|
|
|
description: '零风险体验真实交易,学习投资策略',
|
2026-03-26 00:00:27 +08:00
|
|
|
imagePath: 'assets/images/onboarding_2.png', // 替换为你的图片
|
2026-04-05 23:37:27 +08:00
|
|
|
gradientColors: [AppColorScheme.darkTertiary, AppColorScheme.darkTertiaryContainer],
|
2026-03-25 23:56:23 +08:00
|
|
|
),
|
|
|
|
|
_OnboardingItem(
|
|
|
|
|
title: '资产管理',
|
|
|
|
|
description: '清晰的资产概览,轻松管理你的投资组合',
|
2026-03-26 00:00:27 +08:00
|
|
|
imagePath: 'assets/images/onboarding_3.png', // 替换为你的图片
|
2026-04-05 23:37:27 +08:00
|
|
|
gradientColors: [AppColorScheme.darkSecondary, AppColorScheme.darkSecondaryFixed],
|
2026-03-25 23:56:23 +08:00
|
|
|
),
|
|
|
|
|
_OnboardingItem(
|
|
|
|
|
title: '安全可靠',
|
|
|
|
|
description: '数据加密存储,保护你的隐私安全',
|
2026-03-26 00:00:27 +08:00
|
|
|
imagePath: 'assets/images/onboarding_4.png', // 替换为你的图片
|
2026-04-05 23:37:27 +08:00
|
|
|
gradientColors: [AppColorScheme.darkPrimaryFixed, AppColorScheme.darkPrimaryFixedDim],
|
2026-03-25 23:56:23 +08:00
|
|
|
),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
_pageController.dispose();
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _nextPage() {
|
|
|
|
|
if (_currentPage < _items.length - 1) {
|
|
|
|
|
_pageController.nextPage(
|
|
|
|
|
duration: const Duration(milliseconds: 400),
|
|
|
|
|
curve: Curves.easeInOut,
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
_completeOnboarding();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _skip() {
|
|
|
|
|
_completeOnboarding();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _completeOnboarding() async {
|
|
|
|
|
await LocalStorage.setBool('onboarding_completed', true);
|
|
|
|
|
widget.onComplete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Scaffold(
|
2026-04-06 01:58:08 +08:00
|
|
|
backgroundColor: context.colors.surface,
|
2026-03-25 23:56:23 +08:00
|
|
|
body: SafeArea(
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
// 顶部跳过按钮
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
|
horizontal: AppSpacing.lg,
|
|
|
|
|
vertical: AppSpacing.md,
|
|
|
|
|
),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
|
children: [
|
|
|
|
|
TextButton(
|
|
|
|
|
onPressed: _skip,
|
|
|
|
|
child: Text(
|
|
|
|
|
'跳过',
|
2026-04-05 23:37:27 +08:00
|
|
|
style: AppTextStyles.headlineMedium(context).copyWith(
|
2026-04-06 01:58:08 +08:00
|
|
|
color: context.colors.onSurfaceVariant,
|
2026-03-25 23:56:23 +08:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
// 页面内容
|
|
|
|
|
Expanded(
|
|
|
|
|
child: PageView.builder(
|
|
|
|
|
controller: _pageController,
|
|
|
|
|
onPageChanged: (index) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_currentPage = index;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
itemCount: _items.length,
|
|
|
|
|
itemBuilder: (context, index) {
|
2026-04-06 01:58:08 +08:00
|
|
|
return _buildPage(_items[index]);
|
2026-03-25 23:56:23 +08:00
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
// 底部指示器和按钮
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.fromLTRB(
|
|
|
|
|
AppSpacing.lg,
|
|
|
|
|
AppSpacing.md,
|
|
|
|
|
AppSpacing.lg,
|
|
|
|
|
AppSpacing.xl,
|
|
|
|
|
),
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
// 页面指示器
|
|
|
|
|
Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: List.generate(
|
|
|
|
|
_items.length,
|
2026-04-06 01:58:08 +08:00
|
|
|
(index) => _buildIndicator(index),
|
2026-03-25 23:56:23 +08:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: AppSpacing.xl),
|
|
|
|
|
// 下一步/开始按钮
|
|
|
|
|
SizedBox(
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
height: 56,
|
|
|
|
|
child: ElevatedButton(
|
|
|
|
|
onPressed: _nextPage,
|
|
|
|
|
style: ElevatedButton.styleFrom(
|
2026-04-06 01:58:08 +08:00
|
|
|
backgroundColor: context.colors.primary,
|
|
|
|
|
foregroundColor: context.colors.onPrimary,
|
2026-03-25 23:56:23 +08:00
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(AppRadius.lg),
|
|
|
|
|
),
|
|
|
|
|
elevation: 0,
|
|
|
|
|
),
|
|
|
|
|
child: Text(
|
|
|
|
|
_currentPage == _items.length - 1 ? '开始使用' : '下一步',
|
2026-04-05 23:37:27 +08:00
|
|
|
style: AppTextStyles.headlineLarge(context).copyWith(
|
2026-03-25 23:56:23 +08:00
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-06 01:58:08 +08:00
|
|
|
Widget _buildPage(_OnboardingItem item) {
|
2026-03-25 23:56:23 +08:00
|
|
|
return Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.xl),
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
2026-03-26 00:00:27 +08:00
|
|
|
// 图标/图片容器
|
2026-03-25 23:56:23 +08:00
|
|
|
Container(
|
2026-03-26 00:00:27 +08:00
|
|
|
width: 200,
|
|
|
|
|
height: 200,
|
2026-03-25 23:56:23 +08:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
gradient: LinearGradient(
|
|
|
|
|
begin: Alignment.topLeft,
|
|
|
|
|
end: Alignment.bottomRight,
|
|
|
|
|
colors: item.gradientColors,
|
|
|
|
|
),
|
|
|
|
|
shape: BoxShape.circle,
|
|
|
|
|
boxShadow: [
|
|
|
|
|
BoxShadow(
|
|
|
|
|
color: item.gradientColors.first.withValues(alpha: 0.4),
|
|
|
|
|
blurRadius: 40,
|
|
|
|
|
offset: const Offset(0, 20),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
child: Center(
|
2026-03-26 00:00:27 +08:00
|
|
|
child: item.imagePath != null
|
|
|
|
|
? ClipOval(
|
|
|
|
|
child: Image.asset(
|
|
|
|
|
item.imagePath!,
|
|
|
|
|
width: 180,
|
|
|
|
|
height: 180,
|
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
|
errorBuilder: (context, error, stackTrace) {
|
|
|
|
|
// 图片加载失败时显示图标
|
|
|
|
|
return Icon(
|
|
|
|
|
item.icon ?? LucideIcons.image,
|
|
|
|
|
size: 72,
|
2026-04-06 01:58:08 +08:00
|
|
|
color: context.colors.onPrimary,
|
2026-03-26 00:00:27 +08:00
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: Icon(
|
|
|
|
|
item.icon ?? LucideIcons.star,
|
|
|
|
|
size: 72,
|
2026-04-06 01:58:08 +08:00
|
|
|
color: context.colors.onPrimary,
|
2026-03-26 00:00:27 +08:00
|
|
|
),
|
2026-03-25 23:56:23 +08:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: AppSpacing.xxl + AppSpacing.lg),
|
|
|
|
|
// 标题
|
|
|
|
|
Text(
|
|
|
|
|
item.title,
|
2026-04-05 23:37:27 +08:00
|
|
|
style: AppTextStyles.displaySmall(context).copyWith(
|
2026-03-25 23:56:23 +08:00
|
|
|
fontWeight: FontWeight.bold,
|
2026-04-06 01:58:08 +08:00
|
|
|
color: context.colors.onSurface,
|
2026-03-25 23:56:23 +08:00
|
|
|
letterSpacing: -0.5,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: AppSpacing.md),
|
|
|
|
|
// 描述
|
|
|
|
|
Text(
|
|
|
|
|
item.description,
|
|
|
|
|
textAlign: TextAlign.center,
|
2026-04-05 23:37:27 +08:00
|
|
|
style: AppTextStyles.headlineMedium(context).copyWith(
|
2026-04-06 01:58:08 +08:00
|
|
|
color: context.colors.onSurfaceVariant,
|
2026-03-25 23:56:23 +08:00
|
|
|
height: 1.6,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-06 01:58:08 +08:00
|
|
|
Widget _buildIndicator(int index) {
|
2026-03-25 23:56:23 +08:00
|
|
|
final isActive = index == _currentPage;
|
|
|
|
|
|
|
|
|
|
return AnimatedContainer(
|
|
|
|
|
duration: const Duration(milliseconds: 300),
|
|
|
|
|
margin: const EdgeInsets.symmetric(horizontal: AppSpacing.xs),
|
|
|
|
|
width: isActive ? 24 : 8,
|
|
|
|
|
height: 8,
|
|
|
|
|
decoration: BoxDecoration(
|
2026-04-06 01:58:08 +08:00
|
|
|
color: isActive ? context.colors.primary : context.colors.outlineVariant,
|
2026-04-05 23:37:27 +08:00
|
|
|
borderRadius: BorderRadius.circular(AppRadius.sm),
|
2026-03-25 23:56:23 +08:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|