'Problem when fetching data from API, and filling this data into a list, flutter
When I fetch data from the API and fill in this data in a list, I get the following error:
I/flutter ( 4822): my e ::::; type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'BannersModel'
I tried a lot but to no avail:
Code attached below:
class HomeModel {
late bool? status;
late HomeDataModel? data;
HomeModel.fromJeson(Map<String, dynamic> json) {
status = json["status"];
data = HomeDataModel.fromJeson(json["data"]);
}
}
class HomeDataModel {
late List<BannersModel> bannerss = [];
HomeDataModel.fromJeson(Map<String, dynamic> json) {
json["banners"].forEach((e) {
bannerss.add(e);
});
}
}
class BannersModel {
late int? id;
late String? image;
BannersModel.fromJeson(Map<String, dynamic> json) {
id = json["id"];
image = json["image"];
}
}
I think this code is wrong This is a function to fetch data and fill it in the list
void getDataProdc() {
DioHelper.getData(path: "home", token: tokennn).then((value) {
homeProdcModel = HomeModel.fromJeson(value.data);
}).catchError((e) {
print("my e ::::; ${e.toString()}");
});}
If this is excluded: homeProdcModel = HomeModel.fromJeson(value.data);
And we wrote this: print(value.data); Like the code below:
void getDataProdc() {
DioHelper.getData(path: "home", token: tokennn).then((value) {
//homeProdcModel = HomeModel.fromJeson(value.data);
print(value.data);
}).catchError((e) {
print("my e ::::; ${e.toString()}");
});}
I will get a result that it will print all the data, meaning that the call function is correct, but there is a problem in filling in this data in the custom list in the model
This is what was printed using a print code only
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
