Skip to content

Commit

Permalink
refactor(app): add null fallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
tamara-slosarek authored and tamslo committed Jan 7, 2025
1 parent 69b7bc0 commit 8aabaae
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/lib/common/utilities/drug_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ List<GenotypeResult>? getGenotypeResultsForDrug(Drug drug) {
return null;
}
return drug.guidelineGenotypes.map((genotypeKey) =>
UserData.instance.genotypeResults![genotypeKey] ??
// Should not be null but to be safe
// Should not be null but to be safe
UserData.instance.genotypeResults?[genotypeKey] ??
GenotypeResult.missingResult(
GenotypeKey.extractGene(genotypeKey),
variant: GenotypeKey.maybeExtractVariant(genotypeKey),
Expand Down
2 changes: 1 addition & 1 deletion app/lib/drug_selection/pages/drug_selection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class DrugSelectionPage extends HookWidget {
}

Widget _buildDrugList(BuildContext context, DrugSelectionState state) {
if (DrugsWithGuidelines.instance.drugs!.isEmpty) {
if (DrugsWithGuidelines.instance.drugs?.isEmpty ?? true) {
return Column(
children: [
Text(
Expand Down
18 changes: 10 additions & 8 deletions app/lib/report/pages/report.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,16 @@ class ReportPage extends HookWidget {
}

Iterable<GenotypeResult> _getRelevantGenotypes(List<String>? drugSubset) {
return drugSubset != null
? UserData.instance.genotypeResults!.values.filter((genotypeResult) =>
_getAffectedDrugs(
genotypeResult.key.value,
drugSubset: drugSubset,
).isNotEmpty
)
: UserData.instance.genotypeResults!.values;
return UserData.instance.genotypeResults == null
? []
: drugSubset != null
? UserData.instance.genotypeResults!.values.filter((genotypeResult) =>
_getAffectedDrugs(
genotypeResult.key.value,
drugSubset: drugSubset,
).isNotEmpty
)
: UserData.instance.genotypeResults!.values;
}

List<Widget> _buildGeneCards({
Expand Down

0 comments on commit 8aabaae

Please sign in to comment.