Whenever you need to display a group of related items in the vertical or horizontal direction in mobile. We always need a ListView to display it. Display a specific list is essential almost every app that queries a set of data and returns a list of results, so many apps need to do this at one point or another.
For instance, a list of news items, a list of recipes. It helps you in displaying the data in the form of a scrollable list. Users can then select any list item by clicking on it.
By working through this tutorial, you’ll become familiar with ListView in Flutter and you will be able to fetch data from the server. You can see the final output of the project below.
Let's start its implementation with the following steps.
1. First of all, open main.dart file and create the base of Application. Add application app bar and use builder param. Builder param shows a progress indicator until network fetching result from the server.
2. For fetch data from the server, we have to add HTTP dependency.
after that create networklayer.dart file. We use it to get data from the server. As you can bellow, we using client.get('API URL') method. It will get data and put in compute method for parse it.
once response received from the server, parse it with bellow method. It will create an instance of Country model and parse it.
3. Now, create a ListView widget that will show a group of items. Here, we use a card widget as a container of the list and two texts for display name and capital of the country
At the end merge code snippet and put in its files. Final project structure will look like this.
You can view and download all working files from below.
That's all about the ListView with HTTP in Flutter. If have any query, please feel free to clarify it with comment section below.
For instance, a list of news items, a list of recipes. It helps you in displaying the data in the form of a scrollable list. Users can then select any list item by clicking on it.
By working through this tutorial, you’ll become familiar with ListView in Flutter and you will be able to fetch data from the server. You can see the final output of the project below.
Let's start its implementation with the following steps.
1. First of all, open main.dart file and create the base of Application. Add application app bar and use builder param. Builder param shows a progress indicator until network fetching result from the server.
2. For fetch data from the server, we have to add HTTP dependency.
after that create networklayer.dart file. We use it to get data from the server. As you can bellow, we using client.get('API URL') method. It will get data and put in compute method for parse it.
once response received from the server, parse it with bellow method. It will create an instance of Country model and parse it.
3. Now, create a ListView widget that will show a group of items. Here, we use a card widget as a container of the list and two texts for display name and capital of the country
At the end merge code snippet and put in its files. Final project structure will look like this.
You can view and download all working files from below.
That's all about the ListView with HTTP in Flutter. If have any query, please feel free to clarify it with comment section below.