'API function not returning the list.(It's printing var a but not attend)

API function is working till print(a); The API is returning a list and I'm storing it in a. after that, I'm trying to loop over that list and store it in the List of the Attendance list. but this is not returning a list of AttendenceList, any reason why so.

``` Future<List<AttendenceList>> _getAttendence() async {
final response = await http.post(
  Uri.parse("http://api.sportsb.co.in/api/CustomerAttendance"),
  headers: <String, String>{
    'customer-key': 'EQYGf84gWWMJsi8Bz/73ufdftIdOKyta1YohLogAL5U=',
    'ContentType': 'application/json',
    'Content-Type': 'application/json'
  },
  body: jsonEncode(
    {"Indx": "0", "IdForNew": "0"},
  ),
);
var json = jsonDecode(response
    .body); //jsonDecode() returns a _InternalLinkedHashMap<String, dynamic>

var attendence = json;
var Da = attendence["Data"];
var a = Da["AttendanceList"];
print(a);
List<AttendenceList> attend = [];
for (var p in (a as List)) {
  AttendenceList innerAttendence = AttendenceList(
    p["RowIndex"],
    p["Id"],
    p["InText"],
    p["OutText"],
    p["InDate"],
    p["Duration"],
    p["DateBGColorHEX"],
    p["InColorHEX"],
    p["OutColorHEX"],
    p["DurationColorHEX"],
  );
  attend.add(innerAttendence);
}
print(attend);
return attend;

} }```



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source