Skip to content

Commit

Permalink
fix: language changer not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingkor Roy Tirtho committed Apr 29, 2023
1 parent a5c36bb commit 7b7b1f2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/pages/settings/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 7 additions & 6 deletions lib/provider/user_preferences_provider.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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}),
};
}
}
Expand Down

0 comments on commit 7b7b1f2

Please sign in to comment.