Flutter : JSON parsing with Future Builder

 

 

JSON and FutureBuilder

 FutureBuilder In Flutter - Building Lists with JSON Data - YouTube

A Future which is of type <List<Summary>>
Here the api call is made and the response data is parsed into a List. Since the api response returns a Map (Refer: ‘Example Response’ above) we have to traverse the map to return just the “countries” data from it.

 

In your StatefulWidget (screen) define and declare the variable in the initState() method.
….
Future<List<Summary>> _func;

@override
void initState()
{
_func = fetchSummary();
super.initState();
}

Image for post

Now, in the body: tag of your build Widget call the FutureBuilder
Note: We’ve already declared the _func in initstate() method. The Builder will return a snapshot which will contain the instance of the data.

 Image for post

 Finally, accessing the data List and assigning the values to
DataRows → DataCells.
Note: country.country (index.key)
Similarly all the key-value pairs can be accessed:

country.totalConfirmed.toString(), //converting the integer values
country.newConfirmed.toString(),

Comments

Popular posts from this blog

Flutter : Introduction

How to release your Flutter app

Firebase Cloud Messaging