Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

60
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda