Skip to content

Commit

Permalink
fix(#646): introduce unscrollablePageScaffold
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Aug 23, 2023
1 parent 4989dad commit 77192c7
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 72 deletions.
2 changes: 1 addition & 1 deletion app/lib/common/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export 'l10n.dart';
export 'models/module.dart';
export 'routing/router.dart';
export 'services.dart';
export 'theme.dart';
export 'theme.dart' hide AppBarTheme;
export 'utilities/module.dart';
export 'widgets/module.dart';
23 changes: 22 additions & 1 deletion app/lib/common/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class PharMeTheme {
);
}

// small wrapper for removing some of the boilerplate when defining the textTheme below
// small wrapper for removing some of the boilerplate when defining the
// textTheme below
static TextStyle themeFont(double size,
[FontWeight weight = FontWeight.w400,
double spacing = 0,
Expand Down Expand Up @@ -75,6 +76,26 @@ class PharMeTheme {
static const smallSpace = 8.0;
static const mediumSpace = 16.0;
static const largeSpace = 32.0;

static final appBarTheme = AppBarTheme(
backgroundColor: surfaceColor,
foregroundColor: onSurfaceText,
leadingWidth: smallSpace + mediumSpace
);
}

class AppBarTheme {
AppBarTheme({
required this.backgroundColor,
required this.foregroundColor,
required this.leadingWidth
});

final Color backgroundColor;
final Color foregroundColor;
final double leadingWidth;
final elevation = 0.0;
final centerTitle = false;
}

extension WarningLevelColor on WarningLevel {
Expand Down
95 changes: 45 additions & 50 deletions app/lib/common/widgets/drug_list/drug_items/drug_cards.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,13 @@ List<Widget> buildDrugCards(
}
return warningLevelComparison;
});
return [
SizedBox(height: 8),
...drugs.map((drug) => Column(children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: PharMeTheme.smallSpace),
child: DrugCard(
onTap: () => context.router
.push(DrugRoute(drug: drug))
.then((_) => context.read<DrugListCubit>().search()),
drug: drug,
)
),
SizedBox(height: 12)
]))
];
return drugs.map((drug) => DrugCard(
onTap: () => context.router
.push(DrugRoute(drug: drug))
.then((_) => context.read<DrugListCubit>().search()),

Check warning on line 24 in app/lib/common/widgets/drug_list/drug_items/drug_cards.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/common/widgets/drug_list/drug_items/drug_cards.dart#L22-L24

Added lines #L22 - L24 were not covered by tests
drug: drug,
)
).toList();
}

class DrugCard extends StatelessWidget {
Expand All @@ -50,45 +42,48 @@ class DrugCard extends StatelessWidget {
var drugName = drug.name.capitalize();
if (isInhibitor(drug)) drugName = '$drugName *';

return RoundedCard(
onTap: onTap,
padding: EdgeInsets.all(8),
radius: 16,
color: warningLevel?.color ?? PharMeTheme.indeterminateColor,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(children: [
Icon(warningLevel?.icon ?? indeterminateIcon),
SizedBox(width: 4),
return Padding(
padding: EdgeInsets.symmetric(vertical: PharMeTheme.smallSpace / 2),
child: RoundedCard(
onTap: onTap,
padding: EdgeInsets.all(8),
radius: 16,
color: warningLevel?.color ?? PharMeTheme.indeterminateColor,

Check warning on line 51 in app/lib/common/widgets/drug_list/drug_items/drug_cards.dart

View check run for this annotation

Codecov / codecov/patch

app/lib/common/widgets/drug_list/drug_items/drug_cards.dart#L51

Added line #L51 was not covered by tests
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(children: [
Icon(warningLevel?.icon ?? indeterminateIcon),
SizedBox(width: 4),
Text(
drugName,
style: PharMeTheme.textTheme.titleMedium!
.copyWith(fontWeight: FontWeight.bold),
),
]),
SizedBox(height: 4),
if (drug.annotations.brandNames.isNotEmpty) ...[
SizedBox(width: 4),
Text(
'(${drug.annotations.brandNames.join(', ')})',
style: PharMeTheme.textTheme.titleMedium,
),
],
SizedBox(height: 8),
Text(
drugName,
style: PharMeTheme.textTheme.titleMedium!
.copyWith(fontWeight: FontWeight.bold),
),
]),
SizedBox(height: 4),
if (drug.annotations.brandNames.isNotEmpty) ...[
SizedBox(width: 4),
Text(
'(${drug.annotations.brandNames.join(', ')})',
style: PharMeTheme.textTheme.titleMedium,
drug.annotations.drugclass,
style: PharMeTheme.textTheme.titleSmall,
),
],
SizedBox(height: 8),
Text(
drug.annotations.drugclass,
style: PharMeTheme.textTheme.titleSmall,
),
],
),
),
),
Icon(Icons.chevron_right_rounded),
],
Icon(Icons.chevron_right_rounded),
],
),
),
);
}
Expand Down
59 changes: 47 additions & 12 deletions app/lib/common/widgets/page_scaffold.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
import '../module.dart';

Scaffold pageScaffold(
{required String title,
Widget? barBottom,
List<Widget>? actions,
required List<Widget> body,
Key? key}) {
Text buildTitle(String text) {
return Text(text, style: PharMeTheme.textTheme.headlineLarge);
}

Scaffold pageScaffold({
required String title,
required List<Widget> body,
Widget? barBottom,
List<Widget>? actions,
Key? key,
}) {
return Scaffold(
key: key,
body: CustomScrollView(slivers: [
SliverAppBar(
backgroundColor: PharMeTheme.surfaceColor,
foregroundColor: PharMeTheme.onSurfaceText,
elevation: 0,
leadingWidth: 24,
backgroundColor: PharMeTheme.appBarTheme.backgroundColor,
foregroundColor: PharMeTheme.appBarTheme.foregroundColor,
elevation: PharMeTheme.appBarTheme.elevation,
leadingWidth: PharMeTheme.appBarTheme.leadingWidth,
floating: true,
pinned: true,
snap: false,
centerTitle: false,
title: Text(title, style: PharMeTheme.textTheme.headlineLarge),
centerTitle: PharMeTheme.appBarTheme.centerTitle,
title: buildTitle(title),
actions: actions,
bottom: barBottom == null
? null
Expand All @@ -32,3 +37,33 @@ Scaffold pageScaffold(
]),
);
}

Scaffold unscrollablePageScaffold({
required Widget body,
String? title,
PreferredSizeWidget? barBottom,
List<Widget>? actions,
Key? key,
}) {
return Scaffold(
key: key,
appBar: AppBar(
backgroundColor: PharMeTheme.appBarTheme.backgroundColor,
foregroundColor: PharMeTheme.appBarTheme.foregroundColor,
elevation: PharMeTheme.appBarTheme.elevation,
leadingWidth: PharMeTheme.appBarTheme.leadingWidth,
centerTitle: PharMeTheme.appBarTheme.centerTitle,
title: title == null
? null
: buildTitle(title),
actions: actions,
bottom: barBottom,
),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(PharMeTheme.smallSpace),
child: body,
),
),
);
}
14 changes: 6 additions & 8 deletions app/lib/search/pages/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ class SearchPage extends HookWidget {
await cubit.loadDrugs(useCache: false);
}
});
return pageScaffold(
return unscrollablePageScaffold(
title: context.l10n.tab_drugs,
body: [
DrugSearch(
showFilter: true,
buildDrugItems: buildDrugCards,
cubit: cubit,
)
],
body: DrugSearch(
showFilter: true,
buildDrugItems: buildDrugCards,
cubit: cubit,
),
);
}
}

0 comments on commit 77192c7

Please sign in to comment.