Skip to content

Commit

Permalink
Fix issue #263 Search result not displaying properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
j-fbriere committed Apr 27, 2024
1 parent bbd0680 commit 206815e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/44.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
39 changes: 22 additions & 17 deletions lib/search/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -184,8 +182,9 @@ class _SearchScreenState extends State<_SearchScreen> with SingleTickerProviderS
ChangeNotifierProvider<VideoContextState>(
create: (_) => VideoContextState(prefs.get(optionMediaDefaultMute))),
],
child: Expanded(
child: TabBarView(controller: _tabController, children: [
child: Expanded(child: TabBarView(
controller: _tabController,
children: [
TweetSearchResultList<SearchUsersModel, UserWithExtra>(
key: _searchUsersKey,
queryController: _queryController,
Expand All @@ -204,8 +203,9 @@ class _SearchScreenState extends State<_SearchScreen> with SingleTickerProviderS
store: context.read<SearchTweetsModel>(),
searchFunction: (q, c) => context.read<SearchTweetsModel>().searchTweets(q, PrefService.of(context).get(optionEnhancedSearches), trending: true, cursor: c),
itemBuilder: (context, item) => TweetTile(tweet: item, clickable: true))
])),
)
]
),),
),
],
),
),
Expand Down Expand Up @@ -241,6 +241,7 @@ class TweetSearchResultListState<S extends Store<SearchStatus<T>>, T> extends St
late ScrollController _scrollController;
double _lastOffset = 0;
bool _inAppend = false;
bool _doingRefresh = false;

@override
void initState() {
Expand Down Expand Up @@ -268,10 +269,11 @@ class TweetSearchResultListState<S extends Store<SearchStatus<T>>, T> extends St
_scrollController = ScrollController();
_pagingController = PagingController(firstPageKey: null);
_pagingController.addPageRequestListener((String? cursor) {
fetchResults(cursor);
if (!_doingRefresh) {
fetchResults(cursor);
}
_doingRefresh = false;
});

fetchResults(null);
}

@override
Expand All @@ -283,20 +285,20 @@ class TweetSearchResultListState<S extends Store<SearchStatus<T>>, 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;
Expand Down Expand Up @@ -337,13 +339,16 @@ class TweetSearchResultListState<S extends Store<SearchStatus<T>>, 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);
}
)
),
);
},
);
Expand Down

0 comments on commit 206815e

Please sign in to comment.