From bf21dba275ee7f81480c38cd9c982ab85fb07178 Mon Sep 17 00:00:00 2001 From: ytc1012 <18001193130@163.com> Date: Mon, 24 Nov 2025 11:45:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=87=E6=8D=A2=E8=AF=AD=E8=A8=80=E6=97=A0?= =?UTF-8?q?=E9=9C=80=E9=87=8D=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .claude/settings.local.json | 3 ++- lib/main.dart | 13 +++++++++++++ lib/screens/settings_screen.dart | 10 +++------- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 0b78a4e..2bb2e64 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -31,7 +31,8 @@ "Bash(flutter analyze:*)", "Bash(start \"\" \"f:\\cursor-auto\\focusBuddy\\onboarding-preview.html\")", "Bash(flutter emulators:*)", - "Bash(flutter gen-l10n:*)" + "Bash(flutter gen-l10n:*)", + "Bash(/proc/$PPID/fd/0)" ], "deny": [], "ask": [] diff --git a/lib/main.dart b/lib/main.dart index 7f2c111..eac24ae 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -35,6 +35,12 @@ class MyApp extends StatefulWidget { required this.encouragementService, }); + // Static method to access the state from anywhere (returns void to avoid exposing private type) + static void updateLocale(BuildContext context, String localeCode) { + final state = context.findAncestorStateOfType<_MyAppState>(); + state?.updateLocale(localeCode); + } + @override State createState() => _MyAppState(); } @@ -68,6 +74,13 @@ class _MyAppState extends State { } } + // Method to update locale from settings + void updateLocale(String localeCode) { + setState(() { + _locale = Locale(localeCode); + }); + } + @override Widget build(BuildContext context) { return MaterialApp( diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart index a9c0de5..7ed0188 100644 --- a/lib/screens/settings_screen.dart +++ b/lib/screens/settings_screen.dart @@ -3,6 +3,7 @@ import 'package:shared_preferences/shared_preferences.dart'; import '../l10n/app_localizations.dart'; import '../theme/app_colors.dart'; import '../theme/app_text_styles.dart'; +import '../main.dart'; /// Settings Screen - MVP version with duration presets class SettingsScreen extends StatefulWidget { @@ -74,14 +75,9 @@ class _SettingsScreenState extends State { _selectedLocale = localeCode; }); - // Show snackbar to inform user to restart + // Update locale immediately without restart if (!mounted) return; - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text(AppLocalizations.of(context)!.onboardingReset), - duration: const Duration(seconds: 2), - ), - ); + MyApp.updateLocale(context, localeCode); } @override