pagination work for main page
This commit is contained in:
parent
510e366216
commit
1bcc8372c6
@ -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();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user