Skip to content

Commit

Permalink
(search) Load more search result when 3/4 scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
violet-dev committed Jul 17, 2020
1 parent 7631e5e commit 7895068
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion lib/pages/search/search_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,26 @@ class _SearchPageState extends State<SearchPage>
queryResult = List<QueryResult>();
await loadNextQuery();
});

_scroll.addListener(() {
if (scrollOnce || queryEnd) return;
if (_scroll.offset > _scroll.position.maxScrollExtent / 4 * 3) {
scrollOnce = true;
Future.delayed(Duration(milliseconds: 100)).then((value) async {
print('qqqq');
await loadNextQuery();
scrollOnce = false;
});
}
});
}

bool scrollOnce = false;

Tuple2<QueryManager, String> latestQuery;

ScrollController _scroll = ScrollController();

// https://stackoverflow.com/questions/60643355/is-it-possible-to-have-both-expand-and-contract-effects-with-the-slivers-in
@override
Widget build(BuildContext context) {
Expand All @@ -92,6 +108,7 @@ class _SearchPageState extends State<SearchPage>
padding: EdgeInsets.only(top: statusBarHeight),
child: GestureDetector(
child: CustomScrollView(
controller: _scroll,
physics: const BouncingScrollPhysics(),
slivers: <Widget>[
SliverPersistentHeader(
Expand Down Expand Up @@ -197,6 +214,7 @@ class _SearchPageState extends State<SearchPage>
isOr = false;
tagStates = Map<String, bool>();
groupStates = Map<String, bool>();
queryEnd = false;
await loadNextQuery();
});
// print(latestQuery);
Expand Down Expand Up @@ -363,9 +381,15 @@ class _SearchPageState extends State<SearchPage>

ObjectKey key = ObjectKey(Uuid().v4());

bool queryEnd = false;

Future<void> loadNextQuery() async {
if (queryEnd) return;
var nn = await latestQuery.item1.next();
if (nn.length == 0) return;
if (nn.length == 0) {
queryEnd = true;
return;
}
setState(() {
queryResult.addAll(nn);
});
Expand Down

0 comments on commit 7895068

Please sign in to comment.