39 lines
1.3 KiB
Dart
39 lines
1.3 KiB
Dart
import 'package:collection/collection.dart';
|
|
import '../enumerations.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;
|
|
}
|
|
|
|
/// Sort the given list of sectors of interest, placing [SectorOption.other] at the end.
|
|
List<SectorOption> sortSectorsList(List<SectorOption> sectorList) {
|
|
List<SectorOption> sortedSectors = List.from(sectorList);
|
|
sortedSectors.sort((a, b) {
|
|
// other last
|
|
if (a.name == 'other') return 1;
|
|
if (b.name == 'other') return -1;
|
|
// All others by name ascending
|
|
return a.name.compareTo(b.name);
|
|
});
|
|
return sortedSectors;
|
|
}
|