fix: language changer not working

This commit is contained in:
Kingkor Roy Tirtho 2023-04-29 14:15:28 +06:00
parent a5c36bbb20
commit 7b7b1f2647
2 changed files with 8 additions and 7 deletions

View File

@ -143,7 +143,7 @@ class SettingsPage extends HookConsumerWidget {
value: preferences.locale, value: preferences.locale,
items: [ items: [
DropdownMenuItem( DropdownMenuItem(
value: const Locale("system"), value: const Locale("system", "system"),
child: Text(context.l10n.system_default), child: Text(context.l10n.system_default),
), ),
for (final locale in L10n.all) for (final locale in L10n.all)

View File

@ -1,4 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
@ -67,7 +68,7 @@ class UserPreferences extends PersistedChangeNotifier {
this.downloadLocation = "", this.downloadLocation = "",
this.closeBehavior = CloseBehavior.minimizeToTray, this.closeBehavior = CloseBehavior.minimizeToTray,
this.showSystemTrayIcon = true, this.showSystemTrayIcon = true,
this.locale = const Locale("system"), this.locale = const Locale("system", "system"),
}) : super() { }) : super() {
if (downloadLocation.isEmpty) { if (downloadLocation.isEmpty) {
_getDefaultDownloadDirectory().then( _getDefaultDownloadDirectory().then(
@ -211,10 +212,9 @@ class UserPreferences extends PersistedChangeNotifier {
showSystemTrayIcon = map["showSystemTrayIcon"] ?? showSystemTrayIcon; showSystemTrayIcon = map["showSystemTrayIcon"] ?? showSystemTrayIcon;
locale = Locale( final localeMap = jsonDecode(map["locale"]);
map["locale"]?["lc"] ?? locale.languageCode, locale =
map["locale"]?["cc"] ?? locale.countryCode, localeMap != null ? Locale(localeMap?["lc"], localeMap?["cc"]) : locale;
);
} }
@override @override
@ -233,7 +233,8 @@ class UserPreferences extends PersistedChangeNotifier {
"predownload": predownload, "predownload": predownload,
"closeBehavior": closeBehavior.index, "closeBehavior": closeBehavior.index,
"showSystemTrayIcon": showSystemTrayIcon, "showSystemTrayIcon": showSystemTrayIcon,
"locale": {"lc": locale.languageCode, "cc": locale.countryCode}, "locale":
jsonEncode({"lc": locale.languageCode, "cc": locale.countryCode}),
}; };
} }
} }