Flutter – Lists with JSON

Hi Friends,

This post is a continuation of my previous post here. I would kindly request you to read it once before proceeding.

Let’s begin.

A screencast of this post is available here.

Let’s continue from where we left off.

In our last post we saw how to make a http request and receive a json response right ?

Now open up main.dart file and modify it as shown below.

Let’s break this down.

First, I have removed the button in the center of the screen. Instead of the button, I need to make the http request automatically when the app loads. So, I am overriding the initState() function and making the call.

Once I receive the data, I am simply creating a list with a set of tiles and from the response I got, I am just getting the name, phone number and avatar image alone.

Now run the app and you will see the below screen.


Cool right?

Now let’s write some code to interact with this list. Let’s do a simple onTap interaction. When someone taps a list item, he’ll be taken to a different page where he could see the profile picture or any other details of the particular list item he tapped on.

Open up main.dart and modify it as shown below.

I have created a new class called SecondPage in which I am placing a box on the screen. I am giving a border to this box and then giving a radius of half the value of the height and width of the container in which the box is present. Which means it will now be a circular border.

Then I am simply creating a Material page route and passing the data of the tapped list element. This is then caught by the constructor in the SecondPage class and stored.

Now if you run the app, you will see the below screen.

For instance let’s tap the first element.


Try tapping a different list item. The image of that item would be shown here.


Cool right? That’s it.

In this post we have seen a very simple way to structure and present the data that we receive from a http request.

If you found this helpful, kindly share it with someone and help them too.

Join our Flutter Community – here.

Thanks for reading. Peace.. :)

Liked it? Take a second to support admin on Patreon!