title: LateInitializationError: Field 'data' has not been initialized, got error
body: <p>There is no error in this code but this error is coming after running,
  Can someone please provide an example code of what's needed to solve for the error below?
  &quot;LateInitializationError: Field 'data' has not been initialized, got error&quot;</p>
  <p>This is my_home_page.dart.</p>
  <pre><code>import 'package:fi_digital_earn/DashBoards/PromoCode/provider/myHomePageProvider.dart';
  import 'package:flutter/material.dart';
  import 'package:provider/provider.dart';
  
  class MyHomePage extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: Stack(
          children: [
            ChangeNotifierProvider&lt;MyHomePageProvider&gt;(
              create: (context) =&gt; MyHomePageProvider(),
              child: Consumer&lt;MyHomePageProvider&gt;(
                builder: (context, provider, child) {
                  if (provider.data == null) {
                    // print(&quot;prov $provider.data&quot;);
                    provider.getData(context);
                    return Center(child: CircularProgressIndicator());
                  }
                  // when we have the json loaded... let's put the data into a data table widget
                  return SingleChildScrollView(
                    scrollDirection: Axis.horizontal,
                    // Data table widget in not scrollable so we have to wrap it in a scroll view when we have a large data set..
                    child: SingleChildScrollView(
                      child: DataTable(
                        columns: [
                          // DataColumn(
                          // label: Text('Verified'),
                          // tooltip: 'represents if user is verified.'),
                          DataColumn(
                              label: Text('Pin ID'),
                              tooltip: 'represents first pin id of the user'),
                          DataColumn(
                              label: Text('Pin Name'),
                              tooltip: 'represents pin name of the user'),
                          DataColumn(
                              label: Text('Used/Unused'),
                              tooltip: 'represents Used/Unused of the user'),
                          DataColumn(
                              label: Text('Date'),
                              tooltip: 'represents date of the user'),
                        ],
                        rows: provider.data.results
                            .map((data) =&gt;
                                // we return a DataRow every time
                                DataRow(
                                    // List&lt;DataCell&gt; cells is required in every row
                                    cells: [
                                      // DataCell((data.verified)
                                      //     ? Icon(
                                      //         Icons.verified_user,
                                      //         color: Colors.green,
                                      //       )
                                      //     : Icon(Icons.cancel, color: Colors.red)),
                                      // I want to display a green color icon when user is verified and red when unverified
                                      DataCell(Text(data.pin_id)),
                                      DataCell(Text(data.pin_name)),
                                      DataCell(
                                        RaisedButton(
                                            onPressed: () {},
                                            color: data.used_pin == &quot;1&quot;
                                                ? Colors.green
                                                : Colors.red,
                                            shape: new RoundedRectangleBorder(
                                              borderRadius:
                                                  new BorderRadius.circular(30.0),
                                            ),
                                            // shape: Border.all(
                                            //   color: Colors.purple,
                                            //   width: 2.0,
                                            // ),
                                            // splashColor: Colors.cyan,
                                            // highlightColor: Colors.blue,
                                            child: data.used_pin == &quot;1&quot;
                                                ? Text(&quot;Useed&quot;)
                                                : Text(&quot;Unused&quot;)),
                                      ),
  
                                      DataCell(Text(data.pin_date)),
                                    ]))
                            .toList(),
                      ),
                    ),
                  );
                },
              ),
            ),
          ],
        ),
      );
    }
  }
  </code></pre>
  <p>This is my Provider part.</p>
  <pre><code>import 'dart:convert';
  import 'package:fi_digital_earn/DashBoards/PromoCode/model/myData.dart';
  import 'package:flutter/widgets.dart';
  import 'package:http/http.dart' as http;
  class MyHomePageProvider extends ChangeNotifier {
    late MyData data;
  
    Future getData(context) async {
     
      var url = Uri.parse(
          'https://software.oceonicitsolution.com/hrms/v3/mlm_api/v1/PromoCodeApi.php');
      var response = await http.get(url);
      print(&quot;res${response.body}&quot;);
      // now we have response as String from local json or and API request...
      var mJson = json.decode(response.body);
      // print(&quot;mjson&quot; + mJson);
      this.data = MyData.fromJson(mJson);
      // this.data = http.post(mJson) as MyData;
      this.notifyListeners(); // for callback to view
    }
  }
  </code></pre>
  <p>This is my Model part</p>
  <pre><code>class MyData {
    List&lt;Results&gt; results = [];
  
    MyData.fromJson(Map&lt;String, dynamic&gt; json) {
      // previous = json['previous'];
      // next = json['next'];
      if (json['results'] != null) {
        results = &lt;Results&gt;[];
        json['results'].forEach((v) {
          results.add(new Results.fromJson(v));
        });
      }
    }
  }
  
  class Results {
    String pin_id = &quot;&quot;;
    String pin_name = &quot;&quot;;
    String used_pin = &quot;&quot;;
    String pin_date = &quot;&quot;;
  
    Results.fromJson(Map&lt;String, dynamic&gt; json) {
      pin_id = json['pin_id'];
      pin_name = json['pin_name'];
      used_pin = json['use_unuse'];
      pin_date = json['pin_date'];
    }
  }
  
  </code></pre>