I want to populate datatable with api data. here is my code where i am getting record from api, and creating a datatable.
_getRecord() async{
Dio dio=new Dio();
var data={
'username': getname,
'month': getdate,
};
await dio
.post(localhostUrlAttendanceHistory,data: json.encode(data))
.then((onResponse)async {
print(onResponse.headers);
print(onResponse.statusCode);
print(onResponse.data);
print(onResponse.data['data'][0]['username']);
}).catchError((onerror){
print(onerror.toString());
});
Widget attendanceHistory()=>
DataTable(columns: <DataColumn>[
DataColumn(label: Text("Date"),numeric: true),
DataColumn(label: Text("Time in"),numeric: true),
DataColumn(label: Text("Time out"),numeric: true)
],
rows: [
DataRow(cells: <DataCell>[
DataCell(Text("data")),
DataCell(Text("data")),
DataCell(Text("data"))
])
],
);
@override
Widget build(BuildContext context) {
body:Stack(children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(25, 270, 10, 0),
child: attendanceHistory(),)
])
My api data looks like
data: [{ username: ABC, Date: 2021-06-14, TimeIn: 2:26:07 PM, TimeOut: 4:04;05 PM}]}
please help if anyone know how to do it.