feature/pagination #42

Merged
v4l3n71n merged 10 commits from feature/pagination into main 2025-06-02 21:22:14 +00:00
Showing only changes of commit 1bcc8372c6 - Show all commits

View File

@ -153,21 +153,10 @@ class _MyHomePageState extends State<ListItemMenu> {
}); });
} }
void _decrementFetchCount() {
setState(() {
if (_fetchCount > 0 && filteredPosts.isNotEmpty) {
_fetchCount--;
}
});
}
void _scrollListener() { void _scrollListener() {
if (_scrollController.position.pixels == if (_scrollController.position.pixels ==
_scrollController.position.maxScrollExtent) { _scrollController.position.maxScrollExtent) {
_incrementFetchCount(); _incrementFetchCount();
} else if (_scrollController.position.pixels ==
_scrollController.position.minScrollExtent) {
_decrementFetchCount();
} }
_fetchData(); _fetchData();
} }
@ -475,13 +464,19 @@ class _MyHomePageState extends State<ListItemMenu> {
if (response.statusCode == 200) { if (response.statusCode == 200) {
final List<dynamic> body = json.decode(utf8.decode(response.bodyBytes)); final List<dynamic> body = json.decode(utf8.decode(response.bodyBytes));
print("results fetch : ${body}"); print("results fetch : ${body}");
print("fetch count : ${_fetchCount}");
// Update state after getting the response // Update state after getting the response
setState(() { setState(() {
if (body.isNotEmpty) { if ((body.isNotEmpty) || (_fetchCount > 0)) {
if (body.isEmpty) {
_fetchCount = 0;
}
// If we have results, map them to Events // If we have results, map them to Events
filteredPosts = body filteredPosts.addAll(
.map((e) => Events.fromJson(e as Map<String, dynamic>)) body
.toList(); .map((e) => Events.fromJson(e as Map<String, dynamic>))
.toList(),
);
} else { } else {
// If no results, clear filteredPosts // If no results, clear filteredPosts
filteredPosts.clear(); filteredPosts.clear();