Skip to content

Commit

Permalink
feat: Display current app language at the top of the list
Browse files Browse the repository at this point in the history
  • Loading branch information
Ushie committed Mar 5, 2024
1 parent 4ca7b8a commit aa0575a
Showing 1 changed file with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ class SUpdateLanguage extends BaseViewModel {
final ValueNotifier<String> selectedLanguageCode = ValueNotifier(
'${LocaleSettings.currentLocale.languageCode}-${LocaleSettings.currentLocale.countryCode}',
);
LanguageCodes getLanguageCode(locale) {
return LanguageCodes.fromCode(
'${locale.languageCode}_${locale.countryCode}',
orElse: () => LanguageCodes.fromCode(locale.languageCode),
);
}

final currentlyUsedLanguage = getLanguageCode(LocaleSettings.currentLocale);
// initLang();

// Return a dialog with list for each language supported by the application.
Expand All @@ -53,17 +61,29 @@ class SUpdateLanguage extends BaseViewModel {
builder: (context, value, child) {
return SingleChildScrollView(
child: ListBody(
children: AppLocale.values.map(
(locale) {
final LanguageCodes languageCode = LanguageCodes.fromCode(
'${locale.languageCode}_${locale.countryCode}',
orElse: () => LanguageCodes.fromCode(locale.languageCode),
);

children: [
RadioListTile(
title: Text(currentlyUsedLanguage.englishName),
subtitle: Text(
'${currentlyUsedLanguage.nativeName} (${LocaleSettings.currentLocale.languageCode}${LocaleSettings.currentLocale.countryCode != null ? '-${LocaleSettings.currentLocale.countryCode}' : ''})'),
value:
'${LocaleSettings.currentLocale.languageCode}-${LocaleSettings.currentLocale.countryCode}' ==
selectedLanguageCode.value,
groupValue: true,
onChanged: (value) {
selectedLanguageCode.value =
'${LocaleSettings.currentLocale.languageCode}-${LocaleSettings.currentLocale.countryCode}';
},
),
...AppLocale.values
.where(
(locale) =>
locale.languageCode != currentlyUsedLanguage.code,
)
.map((locale) {
final languageCode = getLanguageCode(locale);
return RadioListTile(
title: Text(
languageCode.englishName,
),
title: Text(languageCode.englishName),
subtitle: Text(
'${languageCode.nativeName} (${locale.languageCode}${locale.countryCode != null ? '-${locale.countryCode}' : ''})',
),
Expand All @@ -75,8 +95,8 @@ class SUpdateLanguage extends BaseViewModel {
'${locale.languageCode}-${locale.countryCode}';
},
);
},
).toList(),
}),
],
),
);
},
Expand Down

0 comments on commit aa0575a

Please sign in to comment.