search back button

This commit is contained in:
MohammadTaha Basiri 2023-10-12 13:53:52 +03:30
parent db4b1f8e00
commit 8291857dac
2 changed files with 23 additions and 4 deletions

View File

@ -95,11 +95,18 @@ class LogoAppBar extends StatelessWidget implements PreferredSizeWidget {
const SizedBox(height: 16), const SizedBox(height: 16),
Consumer<HomeState>( Consumer<HomeState>(
builder: (context, state, child) => SearchField( builder: (context, state, child) => SearchField(
key: ValueKey(state.search),
title: state.currentPageIndex == 3 ? 'رصدهای من' : 'دیدوان', title: state.currentPageIndex == 3 ? 'رصدهای من' : 'دیدوان',
onChanged: (value) => _onChanged(value, context), onChanged: (value) => _onChanged(value, context),
focusNode: FocusNode(), focusNode: FocusNode(),
onFilterButtonPressed: () => _showFilterBottomSheet(context), onFilterButtonPressed: () => _showFilterBottomSheet(context),
isFiltered: state.filtering && state.search == '', isFiltered: state.filtering && state.search == '',
onGoBack: state.filtering
? () {
state.resetFilters(false);
FocusScope.of(context).unfocus();
}
: null,
), ),
), ),
], ],

View File

@ -9,6 +9,7 @@ class SearchField extends StatefulWidget {
final bool? isFiltered; final bool? isFiltered;
final void Function(String value) onChanged; final void Function(String value) onChanged;
final VoidCallback? onFilterButtonPressed; final VoidCallback? onFilterButtonPressed;
final VoidCallback? onGoBack;
const SearchField({ const SearchField({
Key? key, Key? key,
@ -17,6 +18,7 @@ class SearchField extends StatefulWidget {
required this.focusNode, required this.focusNode,
this.onFilterButtonPressed, this.onFilterButtonPressed,
this.isFiltered, this.isFiltered,
this.onGoBack,
}) : super(key: key); }) : super(key: key);
@override @override
@ -107,10 +109,20 @@ class _SearchFieldState extends State<SearchField> {
color: Theme.of(context).colorScheme.primary, color: Theme.of(context).colorScheme.primary,
), ),
), ),
prefixIcon: Icon( 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, DidvanIcons.search_regular,
color: Theme.of(context).colorScheme.text, color: Theme.of(context).colorScheme.text,
), )
: null,
prefixIconColor: Theme.of(context).colorScheme.inputText, prefixIconColor: Theme.of(context).colorScheme.inputText,
enabledBorder: OutlineInputBorder( enabledBorder: OutlineInputBorder(
borderRadius: const BorderRadius.all( borderRadius: const BorderRadius.all(