Skip to content

Commit

Permalink
feat(#691): use drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Feb 21, 2024
1 parent f6ffacb commit aa4ce48
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 26 deletions.
1 change: 0 additions & 1 deletion app/integration_test/search_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:app/common/module.dart';
import 'package:app/common/widgets/drug_list/drug_items/drug_cards.dart';
import 'package:app/search/module.dart';
import 'package:bloc_test/bloc_test.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
Expand Down
1 change: 0 additions & 1 deletion app/lib/common/widgets/drug_list/builder.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import '../../module.dart';
import 'drug_items/drug_cards.dart';

List<Widget> buildDrugList(
BuildContext context,
Expand Down
3 changes: 1 addition & 2 deletions app/lib/common/widgets/drug_search/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:provider/provider.dart';

import '../../../../common/module.dart';
import '../../../drug/widgets/tooltip_icon.dart';
import 'filter_menu.dart';

class DrugSearch extends HookWidget {
DrugSearch({
Expand Down Expand Up @@ -53,7 +52,7 @@ class DrugSearch extends HookWidget {
crossAxisAlignment: CrossAxisAlignment.center,
children: [
..._buildSearchBarItems(context, searchController),
if (showFilter) FilterMenu(cubit, state),
if (showFilter) FilterButton(),
],
),
),
Expand Down
51 changes: 30 additions & 21 deletions app/lib/common/widgets/drug_search/filter_menu.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import '../../module.dart';

class FilterButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return IconButton(
icon: Icon(Icons.filter_list),
color: PharMeTheme.iconColor,
onPressed: Scaffold.of(context).openDrawer,
);
}
}

class FilterMenuItem {
FilterMenuItem({
required bool initialValue,
Expand All @@ -20,32 +31,30 @@ class FilterMenuItem {
}

class FilterMenu extends HookWidget {
const FilterMenu(this.cubit, this.state);
const FilterMenu(this.cubit);

final DrugListCubit cubit;
final DrugListState state;

@override
Widget build(BuildContext context) {
return PopupMenuButton(
icon: Icon(Icons.filter_list),
color: PharMeTheme.onSurfaceColor,
elevation: 0,
itemBuilder: (context) => _menuItems.map(
(item) => PopupMenuItem(child: StatefulBuilder(
builder: (context, setState) {
return item.build(
context,
value: item.value,
statefulOnChange: ([_]) {
final newValue = !item.value;
setState(() => item.value = newValue);
item.updateSearch(newValue);
},
);
}),
),
).toList(),
return SafeArea(
child: Column(
children: _menuItems.map(
(item) => PopupMenuItem(child: StatefulBuilder(
builder: (context, setState) {
return item.build(
context,
value: item.value,
statefulOnChange: ([_]) {
final newValue = !item.value;
setState(() => item.value = newValue);
item.updateSearch(newValue);
},
);
}),
),
).toList(),
),
);
}

Expand Down
2 changes: 2 additions & 0 deletions app/lib/common/widgets/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export 'dialog_content_text.dart';
export 'dialog_wrapper.dart';
export 'drug_list/builder.dart';
export 'drug_list/cubit.dart';
export 'drug_list/drug_items/drug_cards.dart';
export 'drug_search/builder.dart';
export 'drug_search/filter_menu.dart';
export 'error_handler.dart';
export 'full_width_button.dart';
export 'headings.dart';
Expand Down
3 changes: 3 additions & 0 deletions app/lib/common/widgets/page_scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Scaffold unscrollablePageScaffold({
String? title,
String? barBottom,
List<Widget>? actions,
Widget? drawer,
Key? key,
}) {
final appBar = title == null
Expand All @@ -79,6 +80,7 @@ Scaffold unscrollablePageScaffold({
foregroundColor: PharMeTheme.appBarTheme.foregroundColor,
elevation: PharMeTheme.appBarTheme.elevation,
leadingWidth: PharMeTheme.appBarTheme.leadingWidth,
automaticallyImplyLeading: false,
centerTitle: PharMeTheme.appBarTheme.centerTitle,
title: buildTitle(title),
actions: actions,
Expand All @@ -94,5 +96,6 @@ Scaffold unscrollablePageScaffold({
child: body,
),
),
drawer: drawer,
);
}
2 changes: 1 addition & 1 deletion app/lib/search/pages/search.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import '../../../common/module.dart';
import '../../common/widgets/drug_list/drug_items/drug_cards.dart';

@RoutePage()
class SearchPage extends HookWidget {
Expand Down Expand Up @@ -27,6 +26,7 @@ class SearchPage extends HookWidget {
cubit: cubit,
showDrugInteractionIndicator: true,
),
drawer: FilterMenu(cubit),
),
);
}
Expand Down

0 comments on commit aa4ce48

Please sign in to comment.