Skip to content

Commit

Permalink
fix(dictionary): fixed scroll fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
SethCohen committed Apr 10, 2023
1 parent 5cbc6c5 commit c52d3b6
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions src/lib/features/dictionary/dictionary_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,35 @@ class _DictionaryPageState extends State<DictionaryPage> {
return Text('error ${snapshot.error}');
}

return SingleChildScrollView(
child: Wrap(
spacing: 8,
runSpacing: 8,
children: List.generate(
snapshot.docs.length,
(index) {
if (snapshot.hasMore && index + 1 == snapshot.docs.length) {
snapshot.fetchMore();
}
return NotificationListener<ScrollNotification>(
onNotification: (scrollNotification) {
const double threshold = 200.0;

return ConstrainedBox(
constraints: BoxConstraints(
maxWidth: screenWidth * 0.15,
),
child: Flashcard(
card: snapshot.docs[index].data(),
type: CardType.dictionary,
),
);
},
if (scrollNotification.metrics.pixels >=
scrollNotification.metrics.maxScrollExtent - threshold &&
snapshot.hasMore) {
snapshot.fetchMore();
}
return false;
},
child: SingleChildScrollView(
child: Wrap(
spacing: 8,
runSpacing: 8,
children: List.generate(
snapshot.docs.length,
(index) {
return ConstrainedBox(
constraints: BoxConstraints(
maxWidth: screenWidth * 0.15,
),
child: Flashcard(
card: snapshot.docs[index].data(),
type: CardType.dictionary,
),
);
},
),
),
),
);
Expand Down

0 comments on commit c52d3b6

Please sign in to comment.