diff --git a/lib/widget/category_display.dart b/lib/widget/category_display.dart index 51c24f69..874ec168 100644 --- a/lib/widget/category_display.dart +++ b/lib/widget/category_display.dart @@ -40,22 +40,40 @@ class _CategoryDisplayState extends RefreshableState { @override List getAppBarActions(BuildContext context) { - return [ - IconButton( + + List actions = []; + + actions.add( + IconButton( icon: FaIcon(FontAwesomeIcons.search), onPressed: () { + + Map filters = {}; + + if (category != null) { + filters["category"] = "${category.pk}"; + } + showSearch( context: context, - delegate: PartSearchDelegate(context, filters: {"category": "${category.pk}"}) + delegate: PartSearchDelegate(context, filters: filters) ); } - ), - IconButton( - icon: FaIcon(FontAwesomeIcons.edit), - tooltip: I18N.of(context).edit, - onPressed: _editCategoryDialog, - ), - ]; + ) + ); + + if (category != null) { + actions.add( + IconButton( + icon: FaIcon(FontAwesomeIcons.edit), + tooltip: I18N.of(context).edit, + onPressed: _editCategoryDialog, + ) + ); + } + + return actions; + } void _editCategory(Map values) async { @@ -63,7 +81,6 @@ class _CategoryDisplayState extends RefreshableState { final bool result = await category.update(context, values: values); showSnackIcon( - refreshableKey, result ? "Category edited" : "Category editing failed", success: result ); diff --git a/lib/widget/location_display.dart b/lib/widget/location_display.dart index 5c26f418..50f13dd7 100644 --- a/lib/widget/location_display.dart +++ b/lib/widget/location_display.dart @@ -39,22 +39,39 @@ class _LocationDisplayState extends RefreshableState { @override List getAppBarActions(BuildContext context) { - return [ + + List actions = []; + + actions.add( IconButton( icon: FaIcon(FontAwesomeIcons.search), onPressed: () { + + Map filters = {}; + + if (location != null) { + filters["location"] = "${location.pk}"; + } + showSearch( context: context, - delegate: StockSearchDelegate(context, filters: {"location": "${location.pk}"}) + delegate: StockSearchDelegate(context, filters: filters) ); } ), - IconButton( - icon: FaIcon(FontAwesomeIcons.edit), - tooltip: I18N.of(context).edit, - onPressed: _editLocationDialog, - ) - ]; + ); + + if (location != null) { + actions.add( + IconButton( + icon: FaIcon(FontAwesomeIcons.edit), + tooltip: I18N.of(context).edit, + onPressed: _editLocationDialog, + ) + ); + } + + return actions; } void _editLocation(Map values) async { @@ -62,7 +79,6 @@ class _LocationDisplayState extends RefreshableState { final bool result = await location.update(context, values: values); showSnackIcon( - refreshableKey, result ? "Location edited" : "Location editing failed", success: result );