多语言支持
This commit is contained in:
@@ -4,6 +4,7 @@ import '../theme/app_text_styles.dart';
|
||||
import '../models/focus_session.dart';
|
||||
import '../services/storage_service.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import '../l10n/app_localizations.dart';
|
||||
|
||||
/// History Screen - Shows past focus sessions
|
||||
class HistoryScreen extends StatefulWidget {
|
||||
@@ -18,6 +19,7 @@ class _HistoryScreenState extends State<HistoryScreen> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final sessions = _storageService.getAllSessions();
|
||||
final todayTotal = _storageService.getTodayTotalMinutes();
|
||||
final todayDistractions = _storageService.getTodayDistractionCount();
|
||||
@@ -44,16 +46,17 @@ class _HistoryScreenState extends State<HistoryScreen> {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
appBar: AppBar(
|
||||
title: const Text('Your Focus Journey'),
|
||||
title: Text(l10n.yourFocusJourney),
|
||||
backgroundColor: AppColors.background,
|
||||
),
|
||||
body: sessions.isEmpty
|
||||
? _buildEmptyState(context)
|
||||
? _buildEmptyState(context, l10n)
|
||||
: ListView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
children: [
|
||||
// Today's Summary Card
|
||||
_buildTodaySummary(
|
||||
l10n,
|
||||
todayTotal,
|
||||
todayDistractions,
|
||||
todayCompleted,
|
||||
@@ -64,14 +67,14 @@ class _HistoryScreenState extends State<HistoryScreen> {
|
||||
// Sessions by date
|
||||
...sortedDates.map((date) {
|
||||
final dateSessions = sessionsByDate[date]!;
|
||||
return _buildDateSection(date, dateSessions);
|
||||
return _buildDateSection(l10n, date, dateSessions);
|
||||
}),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptyState(BuildContext context) {
|
||||
Widget _buildEmptyState(BuildContext context, AppLocalizations l10n) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(32.0),
|
||||
@@ -84,13 +87,13 @@ class _HistoryScreenState extends State<HistoryScreen> {
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Text(
|
||||
'No focus sessions yet',
|
||||
l10n.noFocusSessionsYet,
|
||||
style: AppTextStyles.headline,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'Start your first session\nto see your progress here!',
|
||||
l10n.startFirstSession,
|
||||
style: AppTextStyles.helperText,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
@@ -105,7 +108,7 @@ class _HistoryScreenState extends State<HistoryScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTodaySummary(int totalMins, int distractions, int completed) {
|
||||
Widget _buildTodaySummary(AppLocalizations l10n, int totalMins, int distractions, int completed) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(24),
|
||||
decoration: BoxDecoration(
|
||||
@@ -117,9 +120,9 @@ class _HistoryScreenState extends State<HistoryScreen> {
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Text(
|
||||
'📅 Today',
|
||||
style: TextStyle(
|
||||
Text(
|
||||
'📅 ${l10n.today}',
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Nunito',
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w600,
|
||||
@@ -137,7 +140,7 @@ class _HistoryScreenState extends State<HistoryScreen> {
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
'$completed ${completed == 1 ? 'session' : 'sessions'}',
|
||||
l10n.sessions(completed),
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Nunito',
|
||||
fontSize: 14,
|
||||
@@ -152,13 +155,13 @@ class _HistoryScreenState extends State<HistoryScreen> {
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildStat('Total', '$totalMins mins', '⏱️'),
|
||||
child: _buildStat('Total', l10n.minutesValue(totalMins, l10n.minutes(totalMins)), '⏱️'),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: _buildStat(
|
||||
'Distractions',
|
||||
'$distractions ${distractions == 1 ? 'time' : 'times'}',
|
||||
l10n.distractionsCount(distractions, l10n.times(distractions)),
|
||||
'🤚',
|
||||
),
|
||||
),
|
||||
@@ -201,10 +204,10 @@ class _HistoryScreenState extends State<HistoryScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDateSection(DateTime date, List<FocusSession> sessions) {
|
||||
Widget _buildDateSection(AppLocalizations l10n, DateTime date, List<FocusSession> sessions) {
|
||||
final isToday = _isToday(date);
|
||||
final dateLabel = isToday
|
||||
? 'Today'
|
||||
? l10n.today
|
||||
: DateFormat('EEE, MMM d').format(date);
|
||||
|
||||
final totalMinutes = sessions.fold<int>(
|
||||
@@ -231,7 +234,7 @@ class _HistoryScreenState extends State<HistoryScreen> {
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
'($totalMinutes mins)',
|
||||
'(${l10n.minutesValue(totalMinutes, l10n.minutes(totalMinutes))})',
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Nunito',
|
||||
fontSize: 16,
|
||||
@@ -244,15 +247,15 @@ class _HistoryScreenState extends State<HistoryScreen> {
|
||||
),
|
||||
|
||||
// Session cards
|
||||
...sessions.map((session) => _buildSessionCard(session)),
|
||||
...sessions.map((session) => _buildSessionCard(l10n, session)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSessionCard(FocusSession session) {
|
||||
Widget _buildSessionCard(AppLocalizations l10n, FocusSession session) {
|
||||
final timeStr = DateFormat('HH:mm').format(session.startTime);
|
||||
final statusEmoji = session.completed ? '✅' : '⏸️';
|
||||
final statusText = session.completed ? 'Completed' : 'Stopped early';
|
||||
final statusText = session.completed ? l10n.completed : l10n.stoppedEarly;
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
@@ -286,14 +289,14 @@ class _HistoryScreenState extends State<HistoryScreen> {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'${session.actualMinutes} ${session.actualMinutes == 1 ? 'minute' : 'minutes'}',
|
||||
l10n.minutesValue(session.actualMinutes, l10n.minutes(session.actualMinutes)),
|
||||
style: AppTextStyles.bodyText,
|
||||
),
|
||||
if (session.distractionCount > 0)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4),
|
||||
child: Text(
|
||||
'🤚 ${session.distractionCount} ${session.distractionCount == 1 ? 'distraction' : 'distractions'}',
|
||||
l10n.distractionsCount(session.distractionCount, l10n.times(session.distractionCount)),
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Nunito',
|
||||
fontSize: 14,
|
||||
|
||||
Reference in New Issue
Block a user