From 206815eeac20c75822ae85c85d314fd2c0c325f6 Mon Sep 17 00:00:00 2001 From: jfbriere Date: Sat, 27 Apr 2024 00:10:49 -0400 Subject: [PATCH] Fix issue #263 Search result not displaying properly. --- .../metadata/android/en-US/changelogs/44.txt | 1 + .../android/en-US/changelogs/default.txt | 1 + lib/search/search.dart | 39 +++++++++++-------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/fastlane/metadata/android/en-US/changelogs/44.txt b/fastlane/metadata/android/en-US/changelogs/44.txt index ef6abed0..161e9992 100644 --- a/fastlane/metadata/android/en-US/changelogs/44.txt +++ b/fastlane/metadata/android/en-US/changelogs/44.txt @@ -3,3 +3,4 @@ * Fix issue #245 UNIQUE constraint failed: twitter_token error at the account renewal when Squawker opens. * Use local time zone for absolute time (PR #245) (thanks @zihu12). * Fix issue #293 Profile search keeps searching for first search term entered, even after deleting it and entering new search term. +* Fix issue #263 Search result not displaying properly. diff --git a/fastlane/metadata/android/en-US/changelogs/default.txt b/fastlane/metadata/android/en-US/changelogs/default.txt index ef6abed0..161e9992 100644 --- a/fastlane/metadata/android/en-US/changelogs/default.txt +++ b/fastlane/metadata/android/en-US/changelogs/default.txt @@ -3,3 +3,4 @@ * Fix issue #245 UNIQUE constraint failed: twitter_token error at the account renewal when Squawker opens. * Use local time zone for absolute time (PR #245) (thanks @zihu12). * Fix issue #293 Profile search keeps searching for first search term entered, even after deleting it and entering new search term. +* Fix issue #263 Search result not displaying properly. diff --git a/lib/search/search.dart b/lib/search/search.dart index e3720a0c..ae14c63a 100644 --- a/lib/search/search.dart +++ b/lib/search/search.dart @@ -122,9 +122,7 @@ class _SearchScreenState extends State<_SearchScreen> with SingleTickerProviderS style: searchTheme.textTheme.titleLarge, textInputAction: TextInputAction.search, onChanged: (String text) { - if (text.isEmpty) { - _resetQuery(); - } + _resetQuery(); }, ), actions: [ @@ -184,8 +182,9 @@ class _SearchScreenState extends State<_SearchScreen> with SingleTickerProviderS ChangeNotifierProvider( create: (_) => VideoContextState(prefs.get(optionMediaDefaultMute))), ], - child: Expanded( - child: TabBarView(controller: _tabController, children: [ + child: Expanded(child: TabBarView( + controller: _tabController, + children: [ TweetSearchResultList( key: _searchUsersKey, queryController: _queryController, @@ -204,8 +203,9 @@ class _SearchScreenState extends State<_SearchScreen> with SingleTickerProviderS store: context.read(), searchFunction: (q, c) => context.read().searchTweets(q, PrefService.of(context).get(optionEnhancedSearches), trending: true, cursor: c), itemBuilder: (context, item) => TweetTile(tweet: item, clickable: true)) - ])), - ) + ] + ),), + ), ], ), ), @@ -241,6 +241,7 @@ class TweetSearchResultListState>, T> extends St late ScrollController _scrollController; double _lastOffset = 0; bool _inAppend = false; + bool _doingRefresh = false; @override void initState() { @@ -268,10 +269,11 @@ class TweetSearchResultListState>, T> extends St _scrollController = ScrollController(); _pagingController = PagingController(firstPageKey: null); _pagingController.addPageRequestListener((String? cursor) { - fetchResults(cursor); + if (!_doingRefresh) { + fetchResults(cursor); + } + _doingRefresh = false; }); - - fetchResults(null); } @override @@ -283,20 +285,20 @@ class TweetSearchResultListState>, T> extends St void resetQuery() { _scrollController.dispose(); - _pagingController.dispose(); + _scrollController = ScrollController(); + _doingRefresh = true; + _pagingController.refresh(); _previousQuery = ''; _previousCursor = null; _lastOffset = 0; - _scrollController = ScrollController(); - _pagingController = PagingController(firstPageKey: null); - _pagingController.addPageRequestListener((String? cursor) { - fetchResults(cursor); - }); } void fetchResults(String? cursor) { if (mounted) { String query = widget.queryController.text; + if (query != _previousQuery) { + cursor = null; + } if (query == _previousQuery && cursor == _previousCursor) { widget.searchFunction('', null); return; @@ -337,13 +339,16 @@ class TweetSearchResultListState>, T> extends St pagingController: _pagingController, addAutomaticKeepAlives: false, builderDelegate: PagedChildBuilderDelegate( + newPageProgressIndicatorBuilder: (context) { + return Container(); + }, itemBuilder: (context, elm, index) { if (!_inAppend) { _lastOffset = _scrollController.offset; } return widget.itemBuilder(context, elm); } - ) + ), ); }, );