From 9a0334814eba079f4acc433ed3ca7282f7a55462 Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Sun, 8 Aug 2021 12:27:21 +0900 Subject: [PATCH] search: fixed leading icon animation --- lib/widgets/home_page.dart | 1 + lib/widgets/search/search_delegate.dart | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) 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,