Skip to content

Commit

Permalink
feat(#718): fix legend separators
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Sep 3, 2024
1 parent a80f6f3 commit c15b242
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 15 additions & 9 deletions app/lib/common/models/drug/warning_level.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,32 @@ extension WarningLevelLegend on List<WarningLevel> {
required String? Function(WarningLevel) getText,
InlineSpan? separator,
}) {
// TODO(tamslo): isLastItem should consider skipped items and consider potential icon margin to add after text, https://github.com/hpi-dhc/PharMe/issues/712
var content = <InlineSpan>[];
for (final (index, warningLevel) in indexed) {
for (final warningLevel in this) {
final text = getText(warningLevel);
if (text.isNullOrEmpty) continue;
final warningLevelIndicator = warningLevel.getDescription(text!);
final isLastItem = index == WarningLevel.values.length - 1;
content = isLastItem
? [ ...content, warningLevelIndicator ]
content = [
...content,
warningLevel.getDescription(text!),
];

}
var separatedContent = <InlineSpan>[];
for (final (index, contentItem) in content.indexed) {
final isLastItem = index == content.length - 1;
separatedContent = isLastItem
? [ ...separatedContent, contentItem ]
: [
...content,
warningLevelIndicator,
...separatedContent,
contentItem,
separator ?? WidgetSpan(
child: SizedBox(width: PharMeTheme.smallSpace * 0.8),
),
];
}
return TextSpan(
style: PharMeTheme.textTheme.bodyMedium,
children: content,
children: separatedContent,
);
}

Expand Down
2 changes: 1 addition & 1 deletion app/lib/report/pages/report.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class GeneCard extends StatelessWidget {
child: Padding(
padding: EdgeInsets.symmetric(
vertical: 2,
horizontal: 4,
horizontal: 6,
),
child: Text.rich(WarningLevel.values.buildLegend(
getText: (warningLevel) {
Expand Down

0 comments on commit c15b242

Please sign in to comment.