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,
items: [
DropdownMenuItem(
value: const Locale("system"),
value: const Locale("system", "system"),
child: Text(context.l10n.system_default),
),
for (final locale in L10n.all)

View File

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