Skip to content

Commit

Permalink
moved around operations in sort function
Browse files Browse the repository at this point in the history
  • Loading branch information
ggurdin committed Dec 13, 2023
1 parent 807a01a commit b021d51
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/pangea/widgets/user_settings/p_language_dropdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,26 @@ class _PLanguageDropdownState extends State<PLanguageDropdown> {
Widget build(BuildContext context) {
final List<LanguageModel> sortedLanguages = widget.languages;
final String systemLang = Localizations.localeOf(context).languageCode;
final List<String> languagePriority = [systemLang, 'en', 'es'];

int sortLanguages(LanguageModel a, LanguageModel b) {
final String aLang = a.langCode;
final String bLang = b.langCode;
if (aLang == bLang) return 0;

final List<String> languagePriority = [systemLang, 'en', 'es'];
final bool aIsPriority = languagePriority.contains(a.langCode);
final bool bIsPriority = languagePriority.contains(b.langCode);
if (!aIsPriority && !bIsPriority) {
return a.getDisplayName(context)!.compareTo(b.getDisplayName(context)!);
}

if (aIsPriority && bIsPriority) {
final int aPriority = languagePriority.indexOf(a.langCode);
final int bPriority = languagePriority.indexOf(b.langCode);
return aPriority - bPriority;
}

if (aIsPriority) return -1;
if (bIsPriority) return 1;

return a.getDisplayName(context)!.compareTo(b.getDisplayName(context)!);
return aIsPriority ? -1 : 1;
}

sortedLanguages.sort((a, b) => sortLanguages(a, b));
Expand Down

0 comments on commit b021d51

Please sign in to comment.