title: In FLutter trying to get JSON had this problem: [ LateInitializationError: Field '_userData@577066488' has not been initialized]
body: <p>I am trying to show the JSON data from a URL to my Flutter application and haven't found any solution yet. because i have the error:</p>
  <p>[LateInitializationError: Field '_userData@577066488' has not been initialized]</p>
  <p>How to show this data in the ListView in Flutter?</p>
  <p>Here is My Complete Project Flutter:</p>
  <p>The Url Parse:</p>
  <h2><a href="http://jsonplaceholder.typicode.com/users" rel="nofollow noreferrer">http://jsonplaceholder.typicode.com/users</a></h2>
  <p><strong>Main.dart</strong></p>
  <pre><code>import 'package:flutter/material.dart';
  import 'json_parse_demo.dart';
  
  void main() {
    runApp(const HomeApp());
  }
  
  class HomeApp extends StatelessWidget {
    const HomeApp({Key? key}) : super(key: key);
  
    @override
    Widget build(BuildContext context) {
      return const MaterialApp(
        debugShowCheckedModeBanner: false,
        home: JsonParseDemo(),
      );
    }
  }
  </code></pre>
  <p><strong>users.dart</strong></p>
  <pre><code>// To parse this JSON data, do
  //
  //     final users = usersFromJson(jsonString);
  
  // ignore_for_file: file_names
  
  import 'dart:convert';
  
  User userFromJson(String str) =&gt; User.fromJson(json.decode(str));
  
  String userToJson(User data) =&gt; json.encode(data.toJson());
  
  class User {
    User({
      required this.user,
    });
  
    List&lt;UserElement&gt; user;
  
    factory User.fromJson(Map&lt;String, dynamic&gt; json) =&gt; User(
          user: List&lt;UserElement&gt;.from(
              json[&quot;User&quot;].map((x) =&gt; UserElement.fromJson(x))),
        );
  
    Map&lt;String, dynamic&gt; toJson() =&gt; {
          &quot;User&quot;: List&lt;dynamic&gt;.from(user.map((x) =&gt; x.toJson())),
        };
  }
  
  class UserElement {
    UserElement({
      required this.id,
      required this.name,
      required this.username,
      required this.email,
      required this.address,
      required this.phone,
      required this.website,
      required this.company,
    });
  
    int id;
    String name;
    String username;
    String email;
    Address address;
    String phone;
    String website;
    Company company;
  
    factory UserElement.fromJson(Map&lt;String, dynamic&gt; json) =&gt; UserElement(
          id: json[&quot;id&quot;],
          name: json[&quot;name&quot;],
          username: json[&quot;username&quot;],
          email: json[&quot;email&quot;],
          address: Address.fromJson(json[&quot;address&quot;]),
          phone: json[&quot;phone&quot;],
          website: json[&quot;website&quot;],
          company: Company.fromJson(json[&quot;company&quot;]),
        );
  
    Map&lt;String, dynamic&gt; toJson() =&gt; {
          &quot;id&quot;: id,
          &quot;name&quot;: name,
          &quot;username&quot;: username,
          &quot;email&quot;: email,
          &quot;address&quot;: address.toJson(),
          &quot;phone&quot;: phone,
          &quot;website&quot;: website,
          &quot;company&quot;: company.toJson(),
        };
  }
  
  class Address {
    Address({
      required this.street,
      required this.suite,
      required this.city,
      required this.zipcode,
      required this.geo,
    });
  
    String street;
    String suite;
    String city;
    String zipcode;
    Geo geo;
  
    factory Address.fromJson(Map&lt;String, dynamic&gt; json) =&gt; Address(
          street: json[&quot;street&quot;],
          suite: json[&quot;suite&quot;],
          city: json[&quot;city&quot;],
          zipcode: json[&quot;zipcode&quot;],
          geo: Geo.fromJson(json[&quot;geo&quot;]),
        );
  
    Map&lt;String, dynamic&gt; toJson() =&gt; {
          &quot;street&quot;: street,
          &quot;suite&quot;: suite,
          &quot;city&quot;: city,
          &quot;zipcode&quot;: zipcode,
          &quot;geo&quot;: geo.toJson(),
        };
  }
  
  class Geo {
    Geo({
      required this.lat,
      required this.lng,
    });
  
    String lat;
    String lng;
  
    factory Geo.fromJson(Map&lt;String, dynamic&gt; json) =&gt; Geo(
          lat: json[&quot;lat&quot;],
          lng: json[&quot;lng&quot;],
        );
  
    Map&lt;String, dynamic&gt; toJson() =&gt; {
          &quot;lat&quot;: lat,
          &quot;lng&quot;: lng,
        };
  }
  
  class Company {
    Company({
      required this.name,
      required this.catchPhrase,
      required this.bs,
    });
  
    String name;
    String catchPhrase;
    String bs;
  
    factory Company.fromJson(Map&lt;String, dynamic&gt; json) =&gt; Company(
          name: json[&quot;name&quot;],
          catchPhrase: json[&quot;catchPhrase&quot;],
          bs: json[&quot;bs&quot;],
        );
  
    Map&lt;String, dynamic&gt; toJson() =&gt; {
          &quot;name&quot;: name,
          &quot;catchPhrase&quot;: catchPhrase,
          &quot;bs&quot;: bs,
        };
  }
  </code></pre>
  <p><strong>servicios.dart</strong></p>
  <pre><code>import 'package:http/http.dart' as http;
  import 'users.dart';
  
  class Services {
    //
    static Uri uri = Uri.parse('http://jsonplaceholder.typicode.com/users');
  
    static Future&lt;List&lt;User&gt;&gt; getUsers() async {
      try {
        final response = await http.get(uri);
        if (200 == response.statusCode) {
          final List&lt;User&gt; users = userFromJson(response.body) as List&lt;User&gt;;
          return users;
        } else {
          return &lt;User&gt;[];
        }
      } catch (e) {
        return &lt;User&gt;[];
      }
    }
  }
  </code></pre>
  <p><strong>json_parse_demo.dart</strong></p>
  <pre><code>// ignore_for_file: unnecessary_null_comparison
  
  import 'package:flutter/material.dart';
  import 'users.dart';
  import 'servicios.dart';
  
  class JsonParseDemo extends StatefulWidget {
    //
    const JsonParseDemo({Key? key}) : super(key: key);
    @override
    _JsonParseDemoState createState() =&gt; _JsonParseDemoState();
  }
  
  class _JsonParseDemoState extends State&lt;JsonParseDemo&gt; {
    //
    late List&lt;User&gt; _users;
    // late bool _loading;
    bool _loading = true; 
    
    @override
    void initState() {
      super.initState();
      _loading = true;
      Services.getUsers().then((users) {
        setState(() {
          _users = users;
          _loading = false;
        });
      });
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text(_loading ? 'Loading...' : 'Users'),
        ),
        body: Container(
          color: Colors.white,
          child: ListView.builder(
            itemCount: null == _users ? 0 : _users.length,
            itemBuilder: (context, index) {
              UserElement user = _users[index] as UserElement;
              return ListTile(
                title: Text(user.name),
                subtitle: Text(user.email),
              );
            },
          ),
        ),
      );
    }
  }
  </code></pre>