Home > OS >  type 'double' is not a subtype of type 'int?' null problem on api call flutter
type 'double' is not a subtype of type 'int?' null problem on api call flutter

Time:08-21

I use this json to list stocks(BIST). enter image description here

enter image description here

CodePudding user response:

As for your model class, there are many fields contains int. It would be nice to if it possible to parse data 1st, then convert to int. Also same goes for double value.

on fromJson

 sembolid: int.tryParse("${json["sembolid"]}"),

while sembolid accept null data you can do it. If the field isnt nullable provide a default value

 sembolid: int.tryParse("${json["sembolid"]}")??0,//here 0 is default value

same thing goes for double value

  • Related