Flutter Infinite Scrolling Pagination for ListView

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
how to load data using a pull to refresh indicator we have a list of items that we display inside a list view around the list view we wrap a refresh indicator and inside the refresh method we put the new items data to some new values with this if you pull to refresh then the refresh method is called and the new items are loaded alternatively you could use the HTTP package to load the new items from a server if the server response is successful then we get from the response body the new items and then we replace the items by the new items let's also go to this URL here you see that we get a list of data and every time we get an individual items in our case we want to access only the ID of each item therefore we simply map over our items and from each item we extract the ID and then we return an item with this number if we pull to refresh now the new items are loaded from the server optionally you can remove the current items before every request and while the items are cleared we show a loading indicator with this a loading indicator is displayed under the new items are loaded how to create an infinite scrolling list view that fetches more data using HTTP we have a list of 15 items that we display inside of a list view once we reach the bottom of the list then we want to load more data simply add one more item to the list view if it is not the last item then we display our normal items and if it is the last item that we have now added then we show a loading indicator as a result if we scroll down the last item is this loading indicator next we add to the list viewer controller that we create within the state within the init State we listen to this scroll controller and check if we have reached the end of the list if this is the case then we want to fetch some more data from the server so in our case we add some more items to the end of the list with this if we reach the end of the list then the new items are appended to our list also make sure to dispose the scroll controller in case it is not needed anymore next you could use the HTTP package to load some items from the server if the response is successful then we get from the response body the new items which we simply add to our current items list let's also go to this website from this URL we load a list of items each item that we load we are only interested in the ID for now therefore let's map over our items from each item we extract the ID and return a text item with this number with this if we reach the end of the list then we load 100 items from the server next we want to make sure that we only load 25 posts from our server next to the Limit you can normally Define a page if it is the page 1 we load the first 25 items if it is the second page then we load 25 more items and so on to make it Dynamic we have a page variable that we add within our state and finally once we have loaded some items from the server we increment the page so that we load next time the next items from the server let's also go to the state and remove the items and instead we fetch then initially some data from the server with this we load 25 5 items from the server if we reach the end then we always load 25 more items of the server if we load less than 25 items from the server we set a flag has more defaults let's also create this flag within our state and within the list view instead of the circular progress indicator for the last item we display then the text no more data to load as a result if we reach the end of the list and there's no more data on the server then it displays no more data to load all also add a is loading flag to your state within the fetch method we make sure that if it is currently loading we are not loading again and if it is not loading then we set the is loading flag to true and when we have finished loading then we set the is loading flag to false with this we make sure if the loading takes longer that we only make one request at a time to the server and finally around the list view we wrap a refresh indicator within the refresh method we reset first of all the stage and then we load all the data our items again with this you can also pull to refresh to make a server request for loading fresh data foreign [Music]
Info
Channel: HeyFlutter․com
Views: 44,260
Rating: undefined out of 5
Keywords: flutter, flutter http, flutter http get, flutter http get example, flutter http get json, flutter http json, flutter http request, flutter infinite list, flutter infinite listview, flutter infinite listview http, flutter infinite scroll, flutter infinite scroll listview, flutter infinite scrolling listview, flutter infinite scrolling listview http get, flutter pagination, flutter pagination listview, infinite scroll flutter, infinite scroll listview flutter, flutter tutorial
Id: FdsqU02xwsE
Channel Id: undefined
Length: 4min 44sec (284 seconds)
Published: Mon Feb 13 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.