Error : type '(dynamic) => Null' is not a subtype of type '(String, dynamic) => void'
Hello guys I am new to flutter and I fetch my data from firebase store and pass to my model, but this error happened! so can you please explain why this happen and how i can i solve this problem,
MainModel.fromJson(dynamic json) {
if (json['tax_center'] != null) {
print(json['tax_center']); //{address: New York, name: centeral}
_taxCenter = [];
json['tax_center'].forEach((v) {
_taxCenter?.add(Tax_center.fromJson(v));
});
}
...
Thanks for your time!
CodePudding user response:
Through print I could see that json['tax_center'] returns Map and not a list.
Using forEach you are treating it as a list.
Try doing something like this:
if (json['tax_center'] != null) {
print(json['tax_center']); //{address: New York, name: centeral}
_taxCenter = [];
_taxCenter?.add(Tax_center.fromJson(json['tax_center']));
}
CodePudding user response:
MainModel.fromJson(json) { //don't use key type
if (json['tax_center'] != null) {
print(json['tax_center']); //{address: New York, name: centeral}
_taxCenter = [];
json['tax_center'].forEach((v) {
_taxCenter?.add(Tax_center.fromJson(v));
});
}
