Closed naveenbharadwaj19 closed 1 year ago
Currently, it is not possible to have a leading widget in flutter_easy_search_bar if you have a drawer or applied it in a context where ModalRoute.of(context).canPop is true, e.g. if used in a widget after Navigator.push. You could Navigator.pushReplacementNamed instead (https://stackoverflow.com/a/44978595). If this is not an option, you instead could change the according code:
Remove these lines in easy_search_bar.dart:
assert(widget.leading == null || !canPop, 'Cannot use leading when back button exists');
And change these lines:
replacement: Visibility( visible: canPop, child: IconTheme( data: iconTheme, child: Padding( padding: const EdgeInsets .only( right: 10), child: IconButton( icon: const Icon( Icons .arrow_back_outlined), onPressed: () => Navigator.pop( context), tooltip: MaterialLocalizations.of( context) .backButtonTooltip), ), ), replacement: Visibility( visible: widget .leading != null, child: Padding( padding: const EdgeInsets .only( right: 10), child: widget .leading, ), replacement: const SizedBox(), ))),
To this:
replacement: Visibility( visible: widget.leading != null, child: Padding( padding: const EdgeInsets .only( right: 10), child: widget.leading, ), replacement: Visibility( visible: canPop, child: IconTheme( data: iconTheme, child: Padding( padding: const EdgeInsets .only( right: 10), child: IconButton( icon: const Icon( Icons .arrow_back_outlined), onPressed: () => Navigator.pop( context), tooltip: MaterialLocalizations.of( context) .backButtonTooltip), ), ), replacement: const SizedBox(), ))),
This changes the behavior of this widget to accepting leading widgets even if there could be a back button and prefer the given widget over the back button. Please note that it makes no sense to use Navigator.push if you do not intend to navigate back.
Maybe I create a pull request later, but for now you are easier set up if you just copy all code and make the changes I proposed.
@hlvs-apps Thank you
How can I remove the back button? I've tried replacing a container in the leading position, but I'm encountering an error. Is there a way to remove the back button?
Adding a container to the leading property gives me this error