多语言支持

This commit is contained in:
ytc1012
2025-11-24 11:25:33 +08:00
parent 2c6ced5c14
commit 4444c401b9
14 changed files with 672 additions and 167 deletions

View File

@@ -1,10 +1,13 @@
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'l10n/app_localizations.dart';
import 'theme/app_theme.dart';
import 'services/storage_service.dart';
import 'services/encouragement_service.dart';
import 'services/notification_service.dart';
import 'screens/home_screen.dart';
import 'screens/onboarding_screen.dart';
import 'screens/settings_screen.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
@@ -39,11 +42,13 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> {
bool _hasCompletedOnboarding = false;
bool _isLoading = true;
Locale? _locale;
@override
void initState() {
super.initState();
_checkOnboardingStatus();
_loadSavedLocale();
}
Future<void> _checkOnboardingStatus() async {
@@ -54,12 +59,32 @@ class _MyAppState extends State<MyApp> {
});
}
Future<void> _loadSavedLocale() async {
final savedLocale = await SettingsScreen.getSavedLocale();
if (savedLocale != null) {
setState(() {
_locale = Locale(savedLocale);
});
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'FocusBuddy',
debugShowCheckedModeBanner: false,
theme: AppTheme.lightTheme,
locale: _locale,
localizationsDelegates: const [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [
Locale('en'),
Locale('zh'),
],
home: _isLoading
? const Scaffold(
body: Center(