Skip to content

Commit

Permalink
refactor(app, warning level): Use map from enum to color/icon
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianWagner2 committed Jul 25, 2022
1 parent f79bfe9 commit 742d3f6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
14 changes: 14 additions & 0 deletions app/lib/common/models/medication/warning_level.dart
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
import 'package:flutter/material.dart';

enum WarningLevel { danger, warning, ok }

final recommendationColorMap = {
WarningLevel.danger.name: Color(0xFFFFAFAF),
WarningLevel.ok.name: Color(0xFF00FF00),
WarningLevel.warning.name: Color(0xFFFFEBCC),
};

final recommendationIconMap = {
WarningLevel.danger.name: Icons.dangerous_rounded,
WarningLevel.ok.name: Icons.check_circle_rounded,
WarningLevel.warning.name: Icons.warning_rounded,
};
5 changes: 1 addition & 4 deletions app/lib/common/pages/medications/medication.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ class MedicationPage extends StatelessWidget {
loading: () => Center(child: CircularProgressIndicator()),
loaded: (medication) => _buildMedicationsPage(
filterUserGuidelines(medication),
isOkGuideline: medication.guidelines[0].warningLevel ==
WarningLevel.ok.toString(),
context: context,
),
),
Expand All @@ -44,7 +42,6 @@ class MedicationPage extends StatelessWidget {

Widget _buildMedicationsPage(
MedicationWithGuidelines medication, {
required bool isOkGuideline,
required BuildContext context,
}) {
return Column(
Expand All @@ -60,7 +57,7 @@ class MedicationPage extends StatelessWidget {
),
SizedBox(height: 12),
if (medication.guidelines.isNotEmpty)
ClinicalAnnotationCard(medication, isOkGuideline: isOkGuideline)
ClinicalAnnotationCard(medication)
else
Text(context.l10n.medications_page_no_guidelines_for_phenotype),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import 'sub_header.dart';
import 'tooltip_icon.dart';

class ClinicalAnnotationCard extends StatelessWidget {
const ClinicalAnnotationCard(this.medication, {required this.isOkGuideline});
const ClinicalAnnotationCard(this.medication);

final MedicationWithGuidelines medication;
final bool isOkGuideline;

@override
Widget build(BuildContext context) {
Expand All @@ -37,7 +36,6 @@ class ClinicalAnnotationCard extends StatelessWidget {
.guidelines[0].cpicRecommendation.isNotNullOrBlank) ...[
RecommendationCard(
medication,
isOkGuideline: isOkGuideline,
context: context,
),
SizedBox(height: 16),
Expand Down
21 changes: 6 additions & 15 deletions app/lib/common/pages/medications/widgets/recommendation_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ import 'sub_header.dart';
class RecommendationCard extends StatelessWidget {
const RecommendationCard(
this.medication, {
required this.isOkGuideline,
required this.context,
});

final MedicationWithGuidelines medication;
final bool isOkGuideline;
final BuildContext context;

@override
Expand All @@ -22,11 +20,8 @@ class RecommendationCard extends StatelessWidget {
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
color: medication.guidelines[0].warningLevel == WarningLevel.danger.name
? Color(0xFFFFAFAF)
: medication.guidelines[0].warningLevel == WarningLevel.ok.name
? Color(0xFF00FF00)
: Color(0xFFFFEBCC),
color: recommendationColorMap[medication.guidelines[0].warningLevel] ??
Color(0xFFFFEBCC),
child: Padding(
padding: const EdgeInsets.all(8),
child: Column(children: [
Expand All @@ -37,14 +32,10 @@ class RecommendationCard extends StatelessWidget {
context.l10n.medications_page_header_recommendation,
),
Icon(
medication.guidelines[0].warningLevel ==
WarningLevel.danger.name
? Icons.dangerous_rounded
: medication.guidelines[0].warningLevel ==
WarningLevel.ok.name
? Icons.check_circle_rounded
: Icons.warning_rounded,
size: 32),
recommendationIconMap[medication.guidelines[0].warningLevel] ??
Icons.warning_rounded,
size: 32,
),
],
),
SizedBox(height: 4),
Expand Down

0 comments on commit 742d3f6

Please sign in to comment.