From 8291857dac2080e1545953f443808ec80b964995 Mon Sep 17 00:00:00 2001 From: MohammadTaha Basiri Date: Thu, 12 Oct 2023 13:53:52 +0330 Subject: [PATCH] search back button --- lib/views/widgets/logo_app_bar.dart | 7 +++++++ lib/views/widgets/search_field.dart | 20 ++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/views/widgets/logo_app_bar.dart b/lib/views/widgets/logo_app_bar.dart index 22dd11e..c0f361c 100644 --- a/lib/views/widgets/logo_app_bar.dart +++ b/lib/views/widgets/logo_app_bar.dart @@ -95,11 +95,18 @@ class LogoAppBar extends StatelessWidget implements PreferredSizeWidget { const SizedBox(height: 16), Consumer( builder: (context, state, child) => SearchField( + key: ValueKey(state.search), title: state.currentPageIndex == 3 ? 'رصدهای من' : 'دیدوان', onChanged: (value) => _onChanged(value, context), focusNode: FocusNode(), onFilterButtonPressed: () => _showFilterBottomSheet(context), isFiltered: state.filtering && state.search == '', + onGoBack: state.filtering + ? () { + state.resetFilters(false); + FocusScope.of(context).unfocus(); + } + : null, ), ), ], diff --git a/lib/views/widgets/search_field.dart b/lib/views/widgets/search_field.dart index 1643ae8..d4e4933 100644 --- a/lib/views/widgets/search_field.dart +++ b/lib/views/widgets/search_field.dart @@ -9,6 +9,7 @@ class SearchField extends StatefulWidget { final bool? isFiltered; final void Function(String value) onChanged; final VoidCallback? onFilterButtonPressed; + final VoidCallback? onGoBack; const SearchField({ Key? key, @@ -17,6 +18,7 @@ class SearchField extends StatefulWidget { required this.focusNode, this.onFilterButtonPressed, this.isFiltered, + this.onGoBack, }) : super(key: key); @override @@ -107,10 +109,20 @@ class _SearchFieldState extends State { color: Theme.of(context).colorScheme.primary, ), ), - prefixIcon: Icon( - DidvanIcons.search_regular, - color: Theme.of(context).colorScheme.text, - ), + prefix: widget.onGoBack != null + ? DidvanIconButton( + gestureSize: 32, + icon: DidvanIcons.back_light, + color: Theme.of(context).colorScheme.text, + onPressed: widget.onGoBack!, + ) + : null, + prefixIcon: widget.onGoBack == null + ? Icon( + DidvanIcons.search_regular, + color: Theme.of(context).colorScheme.text, + ) + : null, prefixIconColor: Theme.of(context).colorScheme.inputText, enabledBorder: OutlineInputBorder( borderRadius: const BorderRadius.all(