积分、成就系统

This commit is contained in:
ytc1012
2025-11-27 13:37:10 +08:00
parent 0195cdf54b
commit 58f6ec39b7
35 changed files with 7786 additions and 199 deletions

View File

@@ -3,9 +3,12 @@ import '../l10n/app_localizations.dart';
import '../theme/app_colors.dart';
import '../theme/app_text_styles.dart';
import '../services/encouragement_service.dart';
import '../services/storage_service.dart';
import '../services/di.dart';
import 'focus_screen.dart';
import 'history_screen.dart';
import 'settings_screen.dart';
import 'profile_screen.dart';
/// Home Screen - Loads default duration from settings
class HomeScreen extends StatefulWidget {
@@ -22,6 +25,7 @@ class HomeScreen extends StatefulWidget {
class _HomeScreenState extends State<HomeScreen> {
int _defaultDuration = 25;
final StorageService _storageService = getIt<StorageService>();
@override
void initState() {
@@ -46,6 +50,7 @@ class _HomeScreenState extends State<HomeScreen> {
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
final progress = _storageService.getUserProgress();
return Scaffold(
backgroundColor: AppColors.background,
@@ -53,8 +58,12 @@ class _HomeScreenState extends State<HomeScreen> {
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// Points Card at the top
_buildPointsCard(context, progress),
const SizedBox(height: 32),
// App Title
Text(
l10n.appTitle,
@@ -100,9 +109,10 @@ class _HomeScreenState extends State<HomeScreen> {
),
),
);
// Reload duration when returning
// Reload duration and refresh points when returning
if (result == true || mounted) {
_loadDefaultDuration();
setState(() {}); // Refresh to show updated points
}
},
child: Row(
@@ -168,4 +178,156 @@ class _HomeScreenState extends State<HomeScreen> {
),
);
}
/// Build points card widget
Widget _buildPointsCard(BuildContext context, progress) {
final l10n = AppLocalizations.of(context)!;
return GestureDetector(
onTap: () async {
// Navigate to ProfileScreen
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const ProfileScreen(),
),
);
// Refresh points when returning from ProfileScreen
setState(() {});
},
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
AppColors.primary.withValues(alpha: 0.1),
AppColors.primary.withValues(alpha: 0.05),
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: AppColors.primary.withValues(alpha: 0.2),
width: 1,
),
),
child: Row(
children: [
// Left side: Points and Level
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
// Points
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
const Text(
'',
style: TextStyle(fontSize: 20),
),
const SizedBox(width: 4),
Text(
'${progress.totalPoints}',
style: const TextStyle(
fontFamily: 'Nunito',
fontSize: 24,
fontWeight: FontWeight.bold,
color: AppColors.primary,
),
),
],
),
Text(
l10n.points,
style: const TextStyle(
fontFamily: 'Nunito',
fontSize: 12,
color: AppColors.textSecondary,
),
),
],
),
// Level
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
const Text(
'🎖️',
style: TextStyle(fontSize: 20),
),
const SizedBox(width: 4),
Text(
'Lv ${progress.level}',
style: const TextStyle(
fontFamily: 'Nunito',
fontSize: 24,
fontWeight: FontWeight.bold,
color: AppColors.primary,
),
),
],
),
Text(
l10n.level,
style: const TextStyle(
fontFamily: 'Nunito',
fontSize: 12,
color: AppColors.textSecondary,
),
),
],
),
],
),
),
// Right side: Check-in status
Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
decoration: BoxDecoration(
color: progress.hasCheckedInToday
? AppColors.success.withValues(alpha: 0.1)
: AppColors.white.withValues(alpha: 0.5),
borderRadius: BorderRadius.circular(12),
),
child: Column(
children: [
Text(
progress.hasCheckedInToday ? '' : '📅',
style: const TextStyle(fontSize: 20),
),
const SizedBox(height: 4),
Text(
progress.hasCheckedInToday ? l10n.checked : l10n.checkIn,
style: TextStyle(
fontFamily: 'Nunito',
fontSize: 10,
color: progress.hasCheckedInToday
? AppColors.success
: AppColors.textSecondary,
fontWeight: FontWeight.w600,
),
),
if (progress.consecutiveCheckIns > 0)
Text(
'🔥 ${progress.consecutiveCheckIns}',
style: const TextStyle(
fontFamily: 'Nunito',
fontSize: 12,
fontWeight: FontWeight.bold,
color: AppColors.primary,
),
),
],
),
),
],
),
),
);
}
}