Skip to content

Commit

Permalink
feature: always show current language (#348)
Browse files Browse the repository at this point in the history
* feature: always show current languge

* resolve mistakes

---------

Co-authored-by: Sagar Raj <[email protected]>
  • Loading branch information
sagarrajgit and Sagar Raj authored Jan 24, 2024
1 parent 78be78a commit 0307faa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
10 changes: 9 additions & 1 deletion lib/app/data/providers/get_storage_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ class GetStorageProvider {
return this;
}

Future<String> readCurrentLanguage() async{
print(_getStorage.read('currentLanguageKey'));
return await _getStorage.read('currentLanguageKey');
}

Future<void> writeCurrentLanguage(String value) async{
await _getStorage.write('currentLanguageKey', value);
}

Future<Locale> readLocale() async {
final languageCode = _getStorage.read('languageCode');

Expand All @@ -25,7 +34,6 @@ class GetStorageProvider {
await _getStorage.write('languageCode', lanCode);
await _getStorage.write('countryCode', countryCode);
}

}


4 changes: 4 additions & 0 deletions lib/app/modules/settings/controllers/settings_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class SettingsController extends GetxController {
final _f24HrsEnabledKey = '24_hours_format';
var isSortedAlarmListEnabled = true.obs;
final _sortedAlarmListKey = 'sorted_alarm_list';
var currentLanguage = 'en_US'.obs;
final _secureStorageProvider = SecureStorageProvider();
final apiKey = TextEditingController();
final currentPoint = LatLng(0, 0).obs;
Expand Down Expand Up @@ -219,6 +220,8 @@ class SettingsController extends GetxController {
isSortedAlarmListEnabled.value = await _secureStorageProvider
.readSortedAlarmListValue(key: _sortedAlarmListKey);

currentLanguage.value=await storage.readCurrentLanguage();

// Store the retrieved API key from the flutter secure storage
String? retrievedAPIKey = await getKey(ApiKeys.openWeatherMap);

Expand Down Expand Up @@ -284,6 +287,7 @@ class SettingsController extends GetxController {
final String countryCode = optionslocales[key]['countryCode'];
Get.updateLocale(Locale(languageCode, countryCode));
local.value = Get.locale.toString();
storage.writeCurrentLanguage(local.value);
storage.writeLocale(languageCode, countryCode);
}
}
20 changes: 12 additions & 8 deletions lib/app/modules/settings/views/language_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ class _LanguageMenuState extends State<LanguageMenu> {
padding: EdgeInsets.only(left: 30),
child: Row(
children: [
DropdownMenu(
menuStyle: MenuStyle(
Obx(
() => DropdownMenu(
menuStyle: MenuStyle(
backgroundColor: MaterialStatePropertyAll(
widget.themeController.isLightMode.value
? kLightSecondaryBackgroundColor
Expand All @@ -48,13 +49,15 @@ class _LanguageMenuState extends State<LanguageMenu> {
),
inputDecorationTheme:
InputDecorationTheme(enabledBorder: InputBorder.none),
trailingIcon: Icon(Icons.arrow_drop_down_outlined,
size: 40.0,
color: widget.themeController.isLightMode.value
? kLightPrimaryTextColor.withOpacity(0.8)
: kprimaryTextColor.withOpacity(0.8)),
trailingIcon: Icon(
Icons.arrow_drop_down_outlined,
size: 40.0,
color: widget.themeController.isLightMode.value
? kLightPrimaryTextColor.withOpacity(0.8)
: kprimaryTextColor.withOpacity(0.8),
),
width: widget.width * 0.78,
initialSelection: 'English',
initialSelection: widget.controller.currentLanguage.value,
label: const Text('Change Language'),
dropdownMenuEntries:
widget.controller.optionslocales.entries.map((e) {
Expand All @@ -73,6 +76,7 @@ class _LanguageMenuState extends State<LanguageMenu> {
onSelected: (newValue) {
widget.controller.updateLocale(newValue!);
},
),
),
],
),
Expand Down

0 comments on commit 0307faa

Please sign in to comment.