Pagination in Flutter using Firebase's Cloud Firestore

Поділитися
Вставка
  • Опубліковано 30 січ 2025

КОМЕНТАРІ • 86

  • @codewithsebastian
    @codewithsebastian 5 місяців тому

    pagination made easy.
    I have always feared this topic and finally faced it

  • @brujala1775
    @brujala1775 Рік тому +1

    i could never understand this before, thank you!

  • @Backyard_Bollywood
    @Backyard_Bollywood 4 роки тому +2

    Alright man, you killed it. You're a great teacher.

  • @jasonli3145
    @jasonli3145 4 роки тому +1

    How u trigger `load more method` in scroll listener , when the ListView cannot be scroll at the beginning?

  • @ahmetcubuk4245
    @ahmetcubuk4245 2 роки тому

    Is it also work when scrolling back to top because when im scrolling back to top, images reload again and i get same problem

  • @ghz13
    @ghz13 3 роки тому

    thanks for posting this man. got exactly what I needed

  • @ModernMonk30
    @ModernMonk30 3 роки тому

    how can we do it if we are using a StreamBuilder to make query to firestore

  • @harishs9808
    @harishs9808 4 роки тому

    Simple and Excellent... Thanks! One correction is to check the length of the List prodducts in the getProducts() function as well, so that getMoreProducts() is not called if the initial list itself is small.

  • @محمدالمطلق-ر6ز
    @محمدالمطلق-ر6ز 5 років тому

    why we did not use the method _getProducts() directly in the listener of the scroll instead of doing another method for loading more products?

  • @HarshSingh-hk8fe
    @HarshSingh-hk8fe 4 роки тому

    such an amazing content, the way you explain things is brilliant :D

  • @ezeget
    @ezeget 4 роки тому

    Great stuff. Well explained. Useful to know. Will be tuning in for more if this. Keep em coming please. If you have something on more generic custom API calls that’s what I’m looking for. No doubt it’s on here just need to hunt around as always with this game.

  • @sauravgupta6166
    @sauravgupta6166 3 роки тому

    Thanks Samarth bro

  • @fiazali6426
    @fiazali6426 3 роки тому

    Good tutorial but 1 problem though!
    In the below statement when we fetch new products :
    => products.addAll(querySnapshot.docs);
    If i don't use this statement in setState() method then the listview.builder() doesn't render/show new content.
    The products array does have new data coming from firebase by pagination but the data is not shown by listview.builder automatically or should i say that the we can't scroll downwards.

  • @shirjeelkhan
    @shirjeelkhan 5 років тому

    Come back after long time... Nice to see you.

  • @HunnyCoders
    @HunnyCoders 5 років тому

    Thanks a lot for this helpful one.
    I was looking for this.
    So clear and described in detail.

  • @vlycie6628
    @vlycie6628 4 роки тому

    simple and very understandable explanation.thanks

  • @abdallahshaban4804
    @abdallahshaban4804 5 років тому

    Will this ensure that updates on firestore are stilll dynamically sent through to the app?

  • @arabnology1
    @arabnology1 2 роки тому

    what about streaming data ?

  • @magazine-2024
    @magazine-2024 3 роки тому

    understand english very little, but you explanation is very good, thank you

  • @yadhuvtk
    @yadhuvtk 3 роки тому

    i getting this error please help me : E/flutter (25414): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Invalid argument: Instance of '_JsonQueryDocumentSnapshot'

  • @MyChanneltutzzzzz
    @MyChanneltutzzzzz 4 роки тому

    Helpful video, is there is a way to use pagination in flutter if i not use cloud firestore ?

  • @feab100
    @feab100 5 років тому +2

    Share link of the Github for this project, please!

  • @manuabhaysinghal3819
    @manuabhaysinghal3819 4 роки тому

    how to implement this with stream builder cuz i am deleting the items

  • @AM-mq3ss
    @AM-mq3ss 4 роки тому

    I'm running into a weird issue.... my Text(products[index].data['title']) is giving me an error on title
    this is the error:
    The operator '[]' isn't defined for the type 'Map Function()'.
    Try defining the operator '[]'.
    please help!

    • @AM-mq3ss
      @AM-mq3ss 4 роки тому

      nevermind figure it out.... just do .data()['title']

  • @TrollMasterMW3
    @TrollMasterMW3 5 років тому +28

    Hey there is a mistake in your code, I believe.
    At the very end, at Line 73 you have " if(querySnapshot.documents.length < _per_page) ". Since you could have 3 more items but if its less than _per_page it would not display.
    It should be " if(querySnapshot.documents.length == 0) " This should fix it.
    I also had to use "Query q = _firestore
    .collection('Post')
    .orderBy('order')
    .startAfterDocument(_lastDocument).limit(_perPage);"
    Thanks for the help otherwise!

    • @tutonmondal6122
      @tutonmondal6122 5 років тому +1

      You're wright

    • @badmanthegreat
      @badmanthegreat 5 років тому

      Or you can pass less than or equal to ...

    • @vzhen
      @vzhen 5 років тому +2

      @@badmanthegreat I believe equal to is not working too. Let say your _perPage is 10 and you have 10 more items then 10 == 10 and return false.

    • @ezeget
      @ezeget 4 роки тому

      Well spotted. Nice work

    • @venkatashravan6353
      @venkatashravan6353 4 роки тому +1

      The code he wrote is actually right, when length < _per_page , he will fetch the documents and for the next time when getmoreProducts is called , it shouldn't fetch , cause we have already fetched all the documents in the last call , when moreProductsAvailable is set to false.

  • @Sammi250
    @Sammi250 5 років тому

    I think there is an issue with the code. Everything you set in the getnextproduct should be under setState(). I am not sure how does your demo code works as expected.

  • @wiltonyu4951
    @wiltonyu4951 5 років тому

    Question, ist better to use flutter over ionic for woocommerce implementation?

  • @VenuGopal-bg7mo
    @VenuGopal-bg7mo 5 років тому +1

    welcome back bro

  • @RogerCouto
    @RogerCouto 5 років тому

    Thanks man, great video. This was exactly a looking for!

  • @amonchowdhury3553
    @amonchowdhury3553 5 років тому +1

    great man. A million thanks.

  • @mavies33
    @mavies33 4 роки тому

    This is very helpful thank you dear Sir.

  • @happynewyearw
    @happynewyearw 5 років тому

    I think you can try to refactor this with rxdart to make the code more readable and the function more reactive?

    • @thesamarthagarwal
      @thesamarthagarwal  5 років тому +1

      Thank you but that wasn't the objective of the video. It is intended for beginners.

    • @happynewyearw
      @happynewyearw 5 років тому

      @@thesamarthagarwal I see, hope to see some video with more advance content such as using rxdart or some other packages! Thanks for the great video!

  • @mnshaikna
    @mnshaikna 5 років тому

    Hi i have a query..
    I have 6 collections and i want my code to iterate itself through the collections..
    So even if i add a new collection, i need not change the code but the iterator will have 7 collections in it?? Any possible solutions??

    • @thesamarthagarwal
      @thesamarthagarwal  5 років тому +1

      Getting list of collections is not possible. You can, however, store names of your collections in a seperate place, may be in a seperate collection/document.

    • @mnshaikna
      @mnshaikna 5 років тому

      @@thesamarthagarwal thanks... I will give it a try and get back... Also I was thinking of creating a new collection and put all the existing collection within it... Similar to what u have suggested...

  • @makemypetgamedevprocess6475
    @makemypetgamedevprocess6475 3 роки тому

    Keep it up 💪

  • @TheSoporte
    @TheSoporte 5 років тому +1

    I like your videos. Thanks

  • @wesleybarnes5376
    @wesleybarnes5376 4 роки тому

    Thank you for making this video

  • @GameCrawl
    @GameCrawl 5 років тому

    how was the data in firestore generated and populated? I have like to try running your program that I have downloaded from github.

    • @thesamarthagarwal
      @thesamarthagarwal  5 років тому

      I wrote a script to add some documents to a collection.

  • @eNONO-ot4zh
    @eNONO-ot4zh 4 роки тому +5

    Now you can use this "paginate_firestore 0.1.1"
    It works very well.
    like this
    return Scaffold(
    body: PaginateFirestore(
    itemBuilder: (context, documentSnapshot) {
    return ListTile(
    title: Text(documentSnapshot.data['title'],
    maxLines: 1,
    style: new TextStyle(
    fontWeight: FontWeight.w500,
    color: Colors.deepOrangeAccent,
    fontSize: 18.0)),
    subtitle: Text(documentSnapshot.data['subtitle'],
    style:
    new TextStyle(fontWeight: FontWeight.w500, fontSize: 14.0)),
    trailing: (documentSnapshot.data['imageUrl'] != null)
    ? Image.network(
    documentSnapshot.data['imageUrl'],
    height: 120.0,
    width: 100.0,
    fit: BoxFit.fill,
    )
    : CircleAvatar(
    backgroundColor: Colors.grey,
    ),
    onTap: () {
    Navigator.of(context).push(MaterialPageRoute(
    builder: (context) => EditArticle(
    Article.fromFirestore(documentSnapshot.data))));
    },
    );
    },
    query: Firestore.instance.collection('articles').orderBy('title'),
    ),

    • @kevinyeung1787
      @kevinyeung1787 4 роки тому

      maybe it is my problems only - the loading time is super slow. Do you encounter any situation like this?

    • @user-jchjkitv77896
      @user-jchjkitv77896 3 роки тому

      Now you can use flutterfire ui for this with built in pagination

  • @guduguminchu
    @guduguminchu 5 років тому

    Nice tutorial, please make same video for remot json data fetching.

  • @MrShri.
    @MrShri. 4 роки тому

    How to do pagination with firebase realtime database ? Tutorial plz or any website u know.. inform me need help

  • @shajeelafzal
    @shajeelafzal 5 років тому +1

    Please make a video on Realtime Database as well.

  • @abdous-i8s
    @abdous-i8s 4 роки тому

    so relaxing

  • @vertobookavis2289
    @vertobookavis2289 5 років тому +1

    sir please help me out in using woocommerce api in ionic 4

    • @thesamarthagarwal
      @thesamarthagarwal  5 років тому +1

      Hi. It is no different from how you do it on Ionic 3.

    • @vertobookavis2289
      @vertobookavis2289 5 років тому +1

      @@thesamarthagarwal
      sir i have followed the course but i am getting few unknown errors errors using ionic 4

    • @vertobookavis2289
      @vertobookavis2289 5 років тому +1

      like can not resolve word crypto and so on up to 24 to 30 lines of errors

    • @thesamarthagarwal
      @thesamarthagarwal  5 років тому

      Vertobook Avis send me an email.

  • @WuschelofDespair
    @WuschelofDespair 4 роки тому

    I checked it out. This is pretty much similar to how I ended up implementing it. But I used the index of the listview builder to reload content, which I personally find cleaner than using a ScrollController. This approach didn’t use a futurebuilder though, because I originally implemented this using a future builder yo wanted to keep it. I had to scrap it though.

    • @mfaraz5075
      @mfaraz5075 2 роки тому

      kinldy explain you index of listview approach

  • @omarh.soliman6814
    @omarh.soliman6814 5 років тому

    i ve made what u did exactly but it gives me that error {Invalid value: Valid value range is empty: -1}

    • @bobobobo3142
      @bobobobo3142 5 років тому

      I am getting same error. Did you find any solution? Please rply!

  • @juangamarra1463
    @juangamarra1463 5 років тому +6

    Me ha sido de mucha utilidad. Gracias.
    Algunas mejoras al código para que sea mas eficiente con la ultima version de cloud_firestore.
    *** Les dejo el codigo abajo:
    ** Obtener LastDocument con querySnapshot.documents.last
    ** Usar condicional querySnapshot.documents.length > 0 para saber si aun hay elementos por cargar.
    Firestore _firestore = Firestore.instance;
    List _products = [];
    bool _loadingProducts = true;
    int _paginationLimit = 20;
    DocumentSnapshot _lastDocument;
    ScrollController _scrollController = ScrollController();
    bool _gettingMoreProducts = false;
    bool _moreProductsIsAvailable = true;
    _getProducts() async {
    Query q = _firestore.collection('producs').limit(_paginationLimit);
    setState(() => _loadingProducts = true);
    QuerySnapshot querySnapshot = await q.getDocuments();
    if (querySnapshot.documents.length > 0) {
    _lastDocument = querySnapshot.documents.last;
    }
    _products.addAll(querySnapshot.documents);
    setState(() => _loadingProducts = false);
    }
    _getMoreProducts() async {
    if (!_moreProductsIsAvailable || _gettingMoreProducts) return;

    _gettingMoreProducts = true;
    Query q = _firestore
    .collection('producs')
    .orderBy('name')
    .startAfterDocument(_lastDocument)
    .limit(_paginationLimit);
    QuerySnapshot querySnapshot = await q.getDocuments();
    if (querySnapshot.documents.length > 0) {
    _lastDocument = querySnapshot.documents.last;
    }
    _moreProductsIsAvailable = querySnapshot.documents.length > 0;
    _products.addAll(querySnapshot.documents);
    _gettingMoreProducts = false;
    setState(() {});
    }

  • @Flutterdev6391
    @Flutterdev6391 4 роки тому

    Thanks man

  • @wiltonyu4951
    @wiltonyu4951 5 років тому

    Hi samarth, I bought your udemy course. Ist possible you release flutter woocommerce guide?

  • @NotAllHeroesWearCapes-101
    @NotAllHeroesWearCapes-101 5 років тому

    Thanks man!

  • @LenVazroctstar
    @LenVazroctstar 5 років тому

    Awesome thanks

  • @syedumair3172
    @syedumair3172 2 роки тому

    Thanks! nice tutorial. Btw you can use startAfterDocument(yourDoc) which takes just DocumentSnapshot

  • @VishvajeetSuryawanshi
    @VishvajeetSuryawanshi 3 роки тому

    thanks a lot

  • @graphic-Pixel
    @graphic-Pixel 5 років тому

    شكرا لك لقد ساعدني كثيرا

  • @chouiteryacine4255
    @chouiteryacine4255 5 років тому

    Thanks a Lot

  • @YuvrajSingh-dt7vr
    @YuvrajSingh-dt7vr 3 роки тому

    Users note to:
    Include all your assignment code inside setstate() in the function(s), it won't work without that.
    ex.
    setState(() {
    _lastDocument = querySnapshot.docs[querySnapshot.docs.length - 1];
    _posts.addAll(querySnapshot.docs);
    _gettingMorePosts = false;
    if (querySnapshot.docs.length < _perPage) {
    _morePostsAvailable = false;
    }
    })

  • @aakashdabas9490
    @aakashdabas9490 4 роки тому +1

    someone arrange for Github code..bruh

  • @WhatIsThisAllAbout
    @WhatIsThisAllAbout 5 років тому

    18 minutes of coding bliss...

  • @jihadatlagh1223
    @jihadatlagh1223 5 років тому

    thank uuu

  • @ahmadzuhdi4921
    @ahmadzuhdi4921 5 років тому

    please next video add image

  • @rajapurva2012
    @rajapurva2012 5 років тому

    Your videos are good but please remove that advt pop up that keeps coming in the bottom right screen. It's distracting.

  • @rara737
    @rara737 4 роки тому

    this is trash code I guess because of "_scrollController"
    I realize that
    int i = 0;
    _scrollController.addListener(() {
    double maxScroll = _scrollController.position.maxScrollExtent;
    double currentScroll = _scrollController.position.pixels;
    double delta = MediaQuery.of(context).size.height * 0.25;
    if (maxScroll - currentScroll < delta) {
    i += 1;
    print("i = " + i.toString());
    _getmoreProducts();
    }
    });
    guess what when I scrolled should be counted only once, but it is counted dozens of times.