24 lines
858 B
Dart
24 lines
858 B
Dart
|
import 'package:collection/collection.dart';
|
||
|
import '../models/language.dart';
|
||
|
|
||
|
/// Compare two lists by their content ignoring their elements order.
|
||
|
bool equalContent(List<dynamic> list1, List<dynamic> list2) {
|
||
|
return const DeepCollectionEquality.unordered().equals(list1, list2);
|
||
|
}
|
||
|
|
||
|
/// Sort the given list of languages so that German appears first, English second, and all other languages follow in alphabetical order.
|
||
|
List<Language> sortLanguageList(List<Language> langList) {
|
||
|
List<Language> sortedLanguages = List.from(langList);
|
||
|
sortedLanguages.sort((a, b) {
|
||
|
// German first
|
||
|
if (a.code == 'de') return -1;
|
||
|
if (b.code == 'de') return 1;
|
||
|
// English second
|
||
|
if (a.code == 'en') return -1;
|
||
|
if (b.code == 'en') return 1;
|
||
|
// All others by name ascending
|
||
|
return a.name.compareTo(b.name);
|
||
|
});
|
||
|
return sortedLanguages;
|
||
|
}
|