Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

56
Views
How to implement Flutter's GetX with Firebase pagination and streams

I'm trying to implement Firebase streams and paging with my GetX. With my implementation the following problem arises. The initial batch of retrieved posts is successfully transmitted and updated in real time. However, the second batch of posts are not updated in real time. It appears that the stream is not linked to the second batch of posts. Here is the code:

 ScrollController scrollController = ScrollController();

CollectionReference get _posts => FirebaseFirestore.instance.collection(FirebaseConstants.postsCollection);

RxList<PostModel> viewPost = RxList<PostModel>([]);

@override
void onInit() {
 super.onInit();
 viewPost.bindStream(getPosts());
}

Stream<List<PostModel>> getPosts() {
 Stream<QuerySnapshot> snapshotStream;

 void handleScroll() {
 if (scrollController.position.maxScrollExtent ==
 scrollController.position.pixels) {
 var lastPost = viewPost.isNotEmpty ? viewPost.last : null;

 _posts
 .orderBy('createdAt', descending: true)
 .startAfter([lastPost!.createdAt])
 .limit(2)
 .snapshots()
 .listen((event) {
 List<PostModel> newPosts = [];
 for (var doc in event.docs) {
 newPosts
 .add(PostModel.fromMap(doc.data() as Map<String, dynamic>));
 }
 viewPost.addAll(newPosts);
 });
 }
 }

 scrollController.addListener(handleScroll);

 snapshotStream =
 _posts.orderBy('createdAt', descending: true).limit(7).snapshots();

 return snapshotStream.map((event) {
 List<PostModel> posts = [];
 for (var doc in event.docs) {
 posts.add(PostModel.fromMap(doc.data() as Map<String, dynamic>));
 }
 return posts;
 });
}

I've tried several different implementations and always encounter the same problem. Posts are retrieved and displayed in the correct order. However, real-time updates work only for the initial batch of posts and not for the rest.

over 2 years ago · Carlos Garzón Colorado
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!