How to Populate ListView with Json API Data

In this Google flutter code example we are going to learn how to populate ListView with Json API Data.

The code is based on flutter version 1.0.0

Main.dart (App entry point)

import 'package:flutter/material.dart';
import 'week4/listview_json_api_task-4.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        // This is the theme of your application.
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
      //home: MyHomePage(title: 'Flutter Demo Home Page'),
      home: ListViewJsonapi(),


import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:http/http.dart' as http;

class ListViewJsonapi extends StatefulWidget {
  _ListViewJsonapiState createState() => _ListViewJsonapiState();

class _ListViewJsonapiState extends State<ListViewJsonapi> {
  final String uri = '';

  Future<List<Users>> _fetchUsers() async {
    var response = await http.get(uri);

    if (response.statusCode == 200) {
      final items = json.decode(response.body).cast<Map<String, dynamic>>();
      List<Users> listOfUsers =<Users>((json) {
        return Users.fromJson(json);

      return listOfUsers;
    } else {
      throw Exception('Failed to load internet');

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Fetching data from JSON - ListView'),
      body: FutureBuilder<List<Users>>(
        future: _fetchUsers(),
        builder: (context, snapshot) {
          if (!snapshot.hasData) return Center(child: CircularProgressIndicator());

          return ListView(
                .map((user) => ListTile(
                      title: Text(,
                      subtitle: Text(,
                      leading: CircleAvatar(
                        child: Text([0],
                            style: TextStyle(
                              fontSize: 18.0,
                              color: Colors.white,

class Users {
  int id;
  String name;
  String username;
  String email;


  factory Users.fromJson(Map<String, dynamic> json) {
    return Users(
      id: json['id'],
      name: json['name'],
      email: json['email'],
      username: json['username'],

flutter listview from json api

If you have any questions or suggestions kindly use the comment box or you can contact us directly through our contact page below.


Add a Comment