No video

Pagination in Flutter using Firebase's Cloud Firestore

  Рет қаралды 38,375

Samarth Agarwal

Samarth Agarwal

Күн бұрын

In this video, you will learn how to implement an infinite scrolling list in Flutter. You will start by learning how to build a simple list by retrieving data from Cloud Firestore. Next, you will learn to use a ScrollController to listen for scrolling events and finally you will learn to use Firestore's SDK method to implement pagination.
Check out my open-source Flutter UI Package on Github here: github.com/sam...
You will find more loading animations and widgets created for you, ready to be used in your apps.
Flutter is Google’s mobile app SDK for crafting high-quality native interfaces on iOS and Android in record time. Flutter works with existing code, is used by developers and organizations around the world, and is free and open source.
Learn to setup Flutter SDK here: flutter.io/
Check out my courses on Udemy if you want to learn how to develop a complete app from start to end in Ionic.
Check out the New Course "Ionic Apps with Firebase on CodeSmash.io: www.codesmash....
Best Seller on Udemy "Ionic 3 Apps for WooCommerce: Build an eCommerce Mobile App": www.udemy.com/...
Ionic Apps with Firebase is a complete course that will teach you two leading app development technologies - Ionic Framework and Firebase. In this course, you will learn all about Ionic and Firebase while working on a real-world social application. At the end of the course, you can publish your app.
We start by learning the basics of Ionic and Firebase. Once introduced to both the technologies, you will learn about building the front-end of the mobile app using the Ionic Framework and the back-end will be taken care of by Firebase. The code for each lecture is available for students to refer to in an easy to use and organized way. A repository will be shared with each student and the code for each lecture is available on a separate Git branch. You can clone the repository as well.
Music Credits - Happy Life by FREDJI / fredjimusic
/ fredjimusic
Music promoted by Audio Library • Happy Life - FREDJI (N...

Пікірлер: 86
@codewithsebastian
@codewithsebastian 13 күн бұрын
pagination made easy. I have always feared this topic and finally faced it
@brujala1775
@brujala1775 7 ай бұрын
i could never understand this before, thank you!
@SinghSanchit
@SinghSanchit 3 жыл бұрын
Alright man, you killed it. You're a great teacher.
@sauravgupta6166
@sauravgupta6166 2 жыл бұрын
Thanks Samarth bro
@ghz13
@ghz13 3 жыл бұрын
thanks for posting this man. got exactly what I needed
@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.
@TrollMasterMW3
@TrollMasterMW3 5 жыл бұрын
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 жыл бұрын
You're wright
@badmanthegreat
@badmanthegreat 4 жыл бұрын
Or you can pass less than or equal to ...
@vzhen
@vzhen 4 жыл бұрын
@@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 3 жыл бұрын
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.
@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.
@HunnyCoders
@HunnyCoders 4 жыл бұрын
Thanks a lot for this helpful one. I was looking for this. So clear and described in detail.
@HarshSingh-hk8fe
@HarshSingh-hk8fe 3 жыл бұрын
such an amazing content, the way you explain things is brilliant :D
@vlycie6628
@vlycie6628 4 жыл бұрын
simple and very understandable explanation.thanks
@magazine-2024
@magazine-2024 3 жыл бұрын
understand english very little, but you explanation is very good, thank you
@shirjeelkhan
@shirjeelkhan 5 жыл бұрын
Come back after long time... Nice to see you.
@mavies33
@mavies33 4 жыл бұрын
This is very helpful thank you dear Sir.
@RogerCouto
@RogerCouto 5 жыл бұрын
Thanks man, great video. This was exactly a looking for!
@jasonli3145
@jasonli3145 4 жыл бұрын
How u trigger `load more method` in scroll listener , when the ListView cannot be scroll at the beginning?
@wesleybarnes5376
@wesleybarnes5376 4 жыл бұрын
Thank you for making this video
@TheSoporte
@TheSoporte 5 жыл бұрын
I like your videos. Thanks
@amonchowdhury3553
@amonchowdhury3553 5 жыл бұрын
great man. A million thanks.
@eNONO-ot4zh
@eNONO-ot4zh 4 жыл бұрын
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 3 жыл бұрын
maybe it is my problems only - the loading time is super slow. Do you encounter any situation like this?
@user-jchjkitv77896
@user-jchjkitv77896 2 жыл бұрын
Now you can use flutterfire ui for this with built in pagination
@ahmetcubuk4245
@ahmetcubuk4245 Жыл бұрын
Is it also work when scrolling back to top because when im scrolling back to top, images reload again and i get same problem
@syedumair3172
@syedumair3172 2 жыл бұрын
Thanks! nice tutorial. Btw you can use startAfterDocument(yourDoc) which takes just DocumentSnapshot
@guduguminchu
@guduguminchu 4 жыл бұрын
Nice tutorial, please make same video for remot json data fetching.
@juangamarra1463
@juangamarra1463 4 жыл бұрын
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(() {}); }
@leonardocoldibelli3965
@leonardocoldibelli3965 4 жыл бұрын
tanks Brother
@abdouseck4894
@abdouseck4894 4 жыл бұрын
so relaxing
@VenuGopal-bg7mo
@VenuGopal-bg7mo 5 жыл бұрын
welcome back bro
@shajeelafzal
@shajeelafzal 5 жыл бұрын
Please make a video on Realtime Database as well.
@wesleybarnes5376
@wesleybarnes5376 4 жыл бұрын
Please!
@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
@user-wf6gx1ju3r
@user-wf6gx1ju3r 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?
@feab100
@feab100 4 жыл бұрын
Share link of the Github for this project, please!
@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.
@MyChanneltutzzzzz
@MyChanneltutzzzzz 4 жыл бұрын
Helpful video, is there is a way to use pagination in flutter if i not use cloud firestore ?
@Flutterdev6391
@Flutterdev6391 3 жыл бұрын
Thanks man
@Sammi250
@Sammi250 4 жыл бұрын
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.
@ModernMonk30
@ModernMonk30 3 жыл бұрын
how can we do it if we are using a StreamBuilder to make query to firestore
@makemypetgamedevprocess6475
@makemypetgamedevprocess6475 3 жыл бұрын
Keep it up 💪
@arabnology1
@arabnology1 2 жыл бұрын
what about streaming data ?
@graphic-Pixel
@graphic-Pixel 5 жыл бұрын
شكرا لك لقد ساعدني كثيرا
@WhatIsThisAllAbout
@WhatIsThisAllAbout 4 жыл бұрын
18 minutes of coding bliss...
@LenVazroctstar
@LenVazroctstar 4 жыл бұрын
Awesome thanks
@yadhuvtk
@yadhuvtk 2 жыл бұрын
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'
@VishvajeetSuryawanshi
@VishvajeetSuryawanshi 3 жыл бұрын
thanks a lot
@abdallahshaban4804
@abdallahshaban4804 4 жыл бұрын
Will this ensure that updates on firestore are stilll dynamically sent through to the app?
@dheerajs2838
@dheerajs2838 4 жыл бұрын
Thanks man!
@manuabhaysinghal3819
@manuabhaysinghal3819 4 жыл бұрын
how to implement this with stream builder cuz i am deleting the items
@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; } })
@chouiteryacine4255
@chouiteryacine4255 5 жыл бұрын
Thanks a Lot
@wiltonyu4951
@wiltonyu4951 5 жыл бұрын
Question, ist better to use flutter over ionic for woocommerce implementation?
@thesamarthagarwal
@thesamarthagarwal 5 жыл бұрын
It is like comparing Apples and Oranges.
@AM-mq3ss
@AM-mq3ss 3 жыл бұрын
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 3 жыл бұрын
nevermind figure it out.... just do .data()['title']
@GameCrawl
@GameCrawl 4 жыл бұрын
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 4 жыл бұрын
I wrote a script to add some documents to a collection.
@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 жыл бұрын
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...
@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 жыл бұрын
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!
@jihadatlagh1223
@jihadatlagh1223 5 жыл бұрын
thank uuu
@MrShri.
@MrShri. 3 жыл бұрын
How to do pagination with firebase realtime database ? Tutorial plz or any website u know.. inform me need help
@ibrahimmammadov9669
@ibrahimmammadov9669 3 жыл бұрын
did you find? I also need that
@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 4 жыл бұрын
I am getting same error. Did you find any solution? Please rply!
@wiltonyu4951
@wiltonyu4951 5 жыл бұрын
Hi samarth, I bought your udemy course. Ist possible you release flutter woocommerce guide?
@thesamarthagarwal
@thesamarthagarwal 5 жыл бұрын
Check this out: pub.dev/packages/woocommerce_api
@aakashdabas9490
@aakashdabas9490 4 жыл бұрын
someone arrange for Github code..bruh
@vertobookavis2289
@vertobookavis2289 5 жыл бұрын
sir please help me out in using woocommerce api in ionic 4
@thesamarthagarwal
@thesamarthagarwal 5 жыл бұрын
Hi. It is no different from how you do it on Ionic 3.
@vertobookavis2289
@vertobookavis2289 5 жыл бұрын
@@thesamarthagarwal sir i have followed the course but i am getting few unknown errors errors using ionic 4
@vertobookavis2289
@vertobookavis2289 5 жыл бұрын
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.
@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.
@ahmadzuhdi4921
@ahmadzuhdi4921 4 жыл бұрын
please next video add image
@rara737
@rara737 3 жыл бұрын
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.
Animated Noise in Flutter using CustomPaint
15:36
Samarth Agarwal
Рет қаралды 7 М.
List Detail with Cloud Firestore in Flutter
16:00
Samarth Agarwal
Рет қаралды 65 М.
ROLLING DOWN
00:20
Natan por Aí
Рет қаралды 11 МЛН
Секрет фокусника! #shorts
00:15
Роман Magic
Рет қаралды 39 МЛН
Complex Animations in Flutter using Rive | Flare
15:44
FilledStacks
Рет қаралды 225 М.
FutureBuilder In Flutter - Building Lists with JSON Data
15:30
Samarth Agarwal
Рет қаралды 252 М.
Top 12 Flutter Tips & Tricks
9:32
Fireship
Рет қаралды 268 М.
Flutter Tutorial - Pagination & Infinite Scrolling - Firestore
12:13
HeyFlutter․com
Рет қаралды 20 М.
Flutter :: Infinite loading and pull-to-refresh - the right way!
13:44
Flutter Provider - Advanced Firebase Data Management
11:08
Fireship
Рет қаралды 143 М.
Pragmatic State Management in Flutter (Google I/O'19)
33:25
Flutter
Рет қаралды 450 М.
Flutter Coding Challenge: Building a Calculator App
25:29
Samarth Agarwal
Рет қаралды 98 М.
flutter firebase send notification to specific user
6:04
dbestech
Рет қаралды 22 М.