diff --git a/lib/widgets/home_page.dart b/lib/widgets/home_page.dart index 86e15c017..d16d53954 100644 --- a/lib/widgets/home_page.dart +++ b/lib/widgets/home_page.dart @@ -161,6 +161,7 @@ class _HomePageState extends State { return SearchPageRoute( delegate: CollectionSearchDelegate( source: source, + canPop: false, initialQuery: _shortcutSearchQuery, ), ); diff --git a/lib/widgets/search/search_delegate.dart b/lib/widgets/search/search_delegate.dart index 65d8f6dbe..2e5e8c438 100644 --- a/lib/widgets/search/search_delegate.dart +++ b/lib/widgets/search/search_delegate.dart @@ -28,6 +28,7 @@ class CollectionSearchDelegate { final CollectionSource source; final CollectionLens? parentCollection; final ValueNotifier expandedSectionNotifier = ValueNotifier(null); + final bool canPop; static const searchHistoryCount = 10; static final typeFilters = [ @@ -45,13 +46,17 @@ class CollectionSearchDelegate { CollectionSearchDelegate({ required this.source, this.parentCollection, + this.canPop = true, String? initialQuery, }) { query = initialQuery ?? ''; } Widget buildLeading(BuildContext context) { - return Navigator.canPop(context) + // use a property instead of checking `Navigator.canPop(context)` + // because the navigator state changes as soon as we press back + // so the leading may mistakenly switch to the close button + return canPop ? IconButton( icon: AnimatedIcon( icon: AnimatedIcons.menu_arrow,