title: Flutter: The method 'map' was called on null. | Adding API Response into datatable row
body: <p>I am trying to add api response data into datatable row.</p>
  <p>My api response is look like this</p>
  <pre><code>{AccessToken: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjoiZm9vYmFyIiwiaWF0IjoxNjIzNzc3MDA0LCJleHAiOjE2MjM3Nzg4MDR9.rp08n01FqkA0lklabii5Ueo0EP0-0Sj4roaSVi-JWQc, data: [{_id: 60c8d7c3ed211c38c4fb2f1b, username: abc, Date: 2021-06-15, TimeIn:  9:39:31 AM, TimeOut: , manager_id: -, code: se-001, __v: 0}, {_id: 60c8d8abed211c38c4fb2f1c, username: abc, Date: 2021-06-15, TimeIn:  9:43:23 AM, TimeOut: , manager_id: -, code: se-001, __v: 0}, {_id: 60c8dee3ed211c38c4fb2f1d, username:abc, Date: 2021-06-15, TimeIn:  10:09:55 AM, TimeOut: , manager_id: -, code: se-001, __v: 0}]}
  </code></pre>
  <p>I want Date, timeIn and timeOut into datatable row</p>
  <p>here is my whole code!!</p>
  <pre><code>
  class MyAttendance extends StatefulWidget {
    @override
    _MyAttendanceState createState() =&gt; _MyAttendanceState();
  }
  
  class _MyAttendanceState extends State&lt;MyAttendance&gt; {
    List&lt;History&gt; _historyList;
  String getdate=&quot;&quot;;
  
      void _getDate() {
      final String formattedDateTime =
          DateFormat('MM').format(DateTime.now()).toString();
      setState(() {
        getdate = formattedDateTime;
       print(&quot;date  &quot;+getdate);
      });
    }
  
    _userDetails() async{
      SharedPreferences myPrefs=await SharedPreferences.getInstance();
      setState(() {
            getname=myPrefs.getString('name');         
          }); 
     }
  
     void initState() {
        _userDetails();  
        _getRecord();
  _getDate();     
      }
  
    _getRecord() async{
      Dio dio=new Dio();
      var data={
        'username':getname,
        'month':getdate
      };
  
        await dio
      .post(localhostUrlAttendanceHistory,data: json.encode(data))
        .then((onResponse)async {
          var jsonData=onResponse.data['data'];
          List&lt;History&gt; historyList = [];
  
          for (var h in jsonData) {
            History history = History(h[&quot;Date&quot;], h[&quot;TimeIn&quot;], h[&quot;TimeOut&quot;],);
            historyList.add(history);
            print(history.date+&quot; &quot;+history.timeIn+&quot; &quot;+history.timeOut);
          }
  
          this.setState(() {
        _historyList = historyList;
      });
          
        }).catchError((onerror){
          print(onerror.toString());
          //showAlertDialog(context);
      });
  
    }
  
    Widget attendanceHistory()=&gt;
    DataTable(columns: &lt;DataColumn&gt;[
      
      DataColumn(label: Text(&quot;Date&quot;),numeric: true),
      DataColumn(label: Text(&quot;Time in&quot;),numeric: true),
      DataColumn(label: Text(&quot;Time out&quot;),numeric: true)
    ],
    rows: 
    _historyList
    .map((element)=&gt;DataRow(
      cells: &lt;DataCell&gt;[
      DataCell(Text(element.date)),
      DataCell(Text(element.timeIn)),
      DataCell(Text(element.timeOut)),
      
    ])
    ));
    
    @override
    Widget build(BuildContext context) {
      return Scaffold(
      body:
      Stack(children: &lt;Widget&gt;[    
         Container(
        padding: EdgeInsets.fromLTRB(135, 210, 10, 0),
        child:
        ElevatedButton(       
            style: ButtonStyle(           
                shape: MaterialStateProperty.all&lt;RoundedRectangleBorder&gt;(
                    RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(20.0),                    
                        )),
            child: Text('Submit',style: TextStyle(fontSize: 20),),         
            onPressed: _getRecord,
          ),
      )),
      Container(
         padding: EdgeInsets.fromLTRB(25, 270, 10, 0),
        child: attendanceHistory(),)  //here i'm calling my datatable widget
      ]));
    }
  }
  class History {
    
    final String date;
    final String timeIn;
    final String timeOut;
    History(this.date, this.timeIn, this.timeOut);
  }
  
  </code></pre>
  <p>here is the <strong>ERROR</strong></p>
  <p>════════ Exception caught by widgets library ═══════════════════════════════════
  The method 'map' was called on null.
  Receiver: null
  Tried calling: map(Closure: (History) =&gt; DataRow)</p>
  <p>when i run the app, it shows this.</p>
  <p><a href="https://i.stack.imgur.com/8jRM5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8jRM5.png" alt="enter image description here" /></a></p>
  <p><strong>UPDATE</strong></p>
  <p>this is what i get from JsonData</p>
  <p>[{_id: 60c8d7c3ed211c38c4fb2f1b, username: abc, Date: 2021-06-15, TimeIn:  9:39:31 AM, TimeOut: , manager_id: -, code: se-001, __v: 0}, {_id: 60c8d8abed211c38c4fb2f1c, username: abc, Date: 2021-06-15, TimeIn:  9:43:23 AM, TimeOut: , manager_id: -, code: se-001, __v: 0}, {_id: 60c8dee3ed211c38c4fb2f1d, username: abc, Date: 2021-06-15, TimeIn:  10:09:55 AM, TimeOut: , manager_id: -, code: se-001, __v: 0}]</p>
  <p>here is its snap</p>
  <p><a href="https://i.stack.imgur.com/Alywh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Alywh.png" alt="enter image description here" /></a></p>
  <p>Please help, if anyknow how to do this.</p>