From 301983f1570482e2efd337ead6b240dc9d4b22dc Mon Sep 17 00:00:00 2001 From: DJDoubleD <34967020+DJDoubleD@users.noreply.github.com> Date: Tue, 27 Aug 2024 00:49:36 +0200 Subject: [PATCH] Update app language without restart --- lib/ui/settings_screen.dart | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/lib/ui/settings_screen.dart b/lib/ui/settings_screen.dart index 387f44e..8ad20dc 100644 --- a/lib/ui/settings_screen.dart +++ b/lib/ui/settings_screen.dart @@ -15,6 +15,7 @@ import 'package:fluttericon/font_awesome5_icons.dart'; import 'package:fluttericon/web_symbols_icons.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:get_it/get_it.dart'; +import 'package:i18n_extension/i18n_extension.dart'; import 'package:logging/logging.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:path_provider/path_provider.dart'; @@ -109,30 +110,13 @@ class _SettingsScreenState extends State { title: Text(l.name), subtitle: Text('${l.locale}-${l.country}'), onTap: () async { + I18n.of(customNavigatorKey.currentContext!).locale = + Locale(l.locale, l.country); setState(() => settings.language = '${l.locale}_${l.country}'); await settings.save(); - showDialog( - context: mainNavigatorKey.currentContext!, - builder: (context) { - return AlertDialog( - title: Text('Language'.i18n), - content: Text( - 'Language changed, please restart ReFreezer to apply!' - .i18n), - actions: [ - TextButton( - child: const Text('OK'), - onPressed: () { - // Close the AlertDialog - Navigator.of(context).pop(); - // Close the SimpleDialog - Navigator.of(context).pop(); - }, - ) - ], - ); - }); + // Close the SimpleDialog + if (context.mounted) Navigator.of(context).pop(); }, ); }))); @@ -1264,7 +1248,7 @@ class _GeneralSettingsState extends State { ListTile( title: Text('Enable equalizer'.i18n), subtitle: Text( - 'Might enable some equalizer apps to work. Requires restart of Freezer' + 'Might enable some equalizer apps to work. Requires restart of ReFreezer' .i18n), leading: const Icon(Icons.equalizer), trailing: Switch(