Skip to content

Commit

Permalink
feat(#569): sort drugs
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Jun 20, 2023
1 parent 6eada9d commit 0a9ac25
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/lib/common/widgets/drug_list/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ List<Widget> _buildDrugCards(
if (filteredDrugs.isEmpty && noDrugsMessage != null) {
return [errorIndicator(noDrugsMessage)];
}
final sortedWarningLevels = [
'WarningLevel.red',
'WarningLevel.yellow',
'WarningLevel.green',
null,
];
filteredDrugs.sort((drugA, drugB) {
final warningLevelComparison = sortedWarningLevels.indexOf(
drugA.userGuideline()?.annotations.warningLevel.toString())
.compareTo(sortedWarningLevels.indexOf(
drugB.userGuideline()?.annotations.warningLevel.toString()));
if (warningLevelComparison == 0) {
return drugA.name.compareTo(drugB.name);
}
return warningLevelComparison;
});
return [
SizedBox(height: 8),
...filteredDrugs.map((drug) => Column(children: [
Expand Down

0 comments on commit 0a9ac25

Please sign in to comment.