title: LateInitializationError: Field '___' has not been initialized
body: <p>I got LateInitializationError: Field '_subjects@100178445' has not been initialized Error for Following Code.</p>
  <p>Json Response as below.</p>
  <pre><code>{
    &quot;success&quot;: 1,
    &quot;subject&quot;: [
      {
        &quot;subject_id&quot;: &quot;5e32874c714fa&quot;,
        &quot;subject_name&quot;: &quot;Account&quot;,
        &quot;image&quot;: &quot;upload/subject/Account.png&quot;,
        &quot;active&quot;: &quot;1&quot;,
        &quot;standard_id&quot;: &quot;5d1594e283e1a&quot;,
        &quot;medium_id&quot;: &quot;5d15938aa1344&quot;
      },
      {
        &quot;subject_id&quot;: &quot;5da9ff659fb7c&quot;,
        &quot;subject_name&quot;: &quot;Biology&quot;,
        &quot;image&quot;: &quot;upload/subject/03_logo-1164x484.png&quot;,
        &quot;active&quot;: &quot;1&quot;,
        &quot;standard_id&quot;: &quot;5d1594e283e1a&quot;,
        &quot;medium_id&quot;: &quot;5d15938aa1344&quot;
      },
      {
        &quot;subject_id&quot;: &quot;5da9ff990b1c6&quot;,
        &quot;subject_name&quot;: &quot;Chemisty&quot;,
        &quot;image&quot;: &quot;upload/subject/02_logo-1168x490.png&quot;,
        &quot;active&quot;: &quot;1&quot;,
        &quot;standard_id&quot;: &quot;5d1594e283e1a&quot;,
        &quot;medium_id&quot;: &quot;5d15938aa1344&quot;
      },
      {
        &quot;subject_id&quot;: &quot;5de76afbd064e&quot;,
        &quot;subject_name&quot;: &quot;Computer&quot;,
        &quot;image&quot;: &quot;upload/subject/07_logo-1169x486.png&quot;,
        &quot;active&quot;: &quot;1&quot;,
        &quot;standard_id&quot;: &quot;5d1594e283e1a&quot;,
        &quot;medium_id&quot;: &quot;5d15938aa1344&quot;
      },
      {
        &quot;subject_id&quot;: &quot;5d788906c431b&quot;,
        &quot;subject_name&quot;: &quot;Devsatya Paperset March 2020&quot;,
        &quot;image&quot;: &quot;upload/subject/04_logo-1174x491.png&quot;,
        &quot;active&quot;: &quot;1&quot;,
        &quot;standard_id&quot;: &quot;5d1594e283e1a&quot;,
        &quot;medium_id&quot;: &quot;5d15938aa1344&quot;
      }
    ]
  }
  </code></pre>
  <p>Model class as bellow in subject_model.dart file.</p>
  <pre><code>// To parse this JSON data, do
  //
  //     final subjectByUser = subjectByUserFromJson(jsonString);
  
  import 'dart:convert';
  
  SubjectByUser subjectByUserFromJson(String str) =&gt;
      SubjectByUser.fromJson(json.decode(str));
  
  String subjectByUserToJson(SubjectByUser data) =&gt; json.encode(data.toJson());
  
  class SubjectByUser {
    SubjectByUser({
      required this.success,
      required this.subject,
    });
  
    int success;
    List&lt;Subject&gt; subject;
  
    factory SubjectByUser.fromJson(Map&lt;String, dynamic&gt; json) =&gt; SubjectByUser(
          success: json[&quot;success&quot;],
          subject:
              List&lt;Subject&gt;.from(json[&quot;subject&quot;].map((x) =&gt; Subject.fromJson(x))),
        );
  
    Map&lt;String, dynamic&gt; toJson() =&gt; {
          &quot;success&quot;: success,
          &quot;subject&quot;: List&lt;dynamic&gt;.from(subject.map((x) =&gt; x.toJson())),
        };
  }
  
  class Subject {
    Subject({
      required this.subjectId,
      required this.subjectName,
      required this.image,
      required this.active,
      required this.standardId,
      required this.mediumId,
    });
  
    String subjectId;
    String subjectName;
    String image;
    String active;
    String standardId;
    String mediumId;
  
    factory Subject.fromJson(Map&lt;String, dynamic&gt; json) =&gt; Subject(
          subjectId: json[&quot;subject_id&quot;],
          subjectName: json[&quot;subject_name&quot;],
          image: json[&quot;image&quot;],
          active: json[&quot;active&quot;],
          standardId: json[&quot;standard_id&quot;],
          mediumId: json[&quot;medium_id&quot;],
        );
  
    Map&lt;String, dynamic&gt; toJson() =&gt; {
          &quot;subject_id&quot;: subjectId,
          &quot;subject_name&quot;: subjectName,
          &quot;image&quot;: image,
          &quot;active&quot;: active,
          &quot;standard_id&quot;: standardId,
          &quot;medium_id&quot;: mediumId,
        };
  }
  </code></pre>
  <p>I created Function as below in apimanager.dart file</p>
  <pre><code>class ApiManager {
    static const String subjectUrl =
        &quot;http://192.168.43.160/sahjanand/api/subject/get_by_user_plan?user_id=609cab2cd5b6c&amp;order_id=1620889722609cd07a601af469889697609cab2cd5b6c&amp;standard_id=5d1594e283e1a&amp;medium_id=5d15938aa1344&quot;;
  
    static Future&lt;List&lt;SubjectByUser&gt;&gt; getSubjectByUser() async {
      try {
        final response = await http.get(Uri.parse(subjectUrl));
        if (response.statusCode == 200) {
          final List&lt;SubjectByUser&gt; subjects =
              subjectByUserFromJson(response.body) as List&lt;SubjectByUser&gt;;
          print(subjects);
          return subjects;
        } else {
          return &lt;SubjectByUser&gt;[];
        }
      } catch (e) {
        // ignore: deprecated_member_use
        return &lt;SubjectByUser&gt;[];
      }
    }
  }
  </code></pre>
  <p>And view code in homepage.dart file as bellow.</p>
  <pre><code>class MyHomePage extends StatefulWidget {
    MyHomePage({Key? key}) : super(key: key);
  
    @override
    _MyHomePageState createState() =&gt; _MyHomePageState();
  }
  
  class _MyHomePageState extends State&lt;MyHomePage&gt; {
    late List&lt;SubjectByUser&gt; _subjects;
    late bool _loading;
  
    @override
    void initState() {
      // TODO: implement initState
      super.initState();
      _loading = true;
      ApiManager.getSubjectByUser().then((subjects) {
        setState(() {
          _subjects = subjects;
          _loading = false;
        });
      });
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text(_loading ? 'Loading...' : 'Subjects'),
        ),
        body: Center(
          child: ListView.builder(
              itemCount: null == _subjects ? 0 : _subjects.length,
              itemBuilder: (context, index) {
                SubjectByUser subjectByUser = _subjects[index];
                return ListTile(
                  title: Text(subjectByUser.success.toString()),
                  subtitle: Text(subjectByUser.subject.length.toString()),
                );
              }),
         
        ),
      );
    }
  }
  </code></pre>
  <p>i got the LateInitializationError: Field '_subjects@100178445' has not been initialized Error.
  So please help me how i solve this error.</p>