Reputation: 185
i have this error when i call the data from api the problem based in DateTime
attribut,
error : Unhandled Exception: type 'Null' is not a subtype of type 'String'
required this.dateTime,
DateTime dateTime;
DateTime.parse(json["dateTime"]),
"dateTime": dateTime.toIso8601String(),
Upvotes: 0
Views: 528
Reputation: 60
Its Null safety issue when you are accessing: json["dateTime"]
this value and parsing into DateTime like:-DateTime.parse(json["dateTime"]
and if this value json["dateTime"]
will be null then this issue will be occure. by changing little bit in your code you'll re-solve this issue.
required this.dateTime,
DateTime dateTime;
DateTime.parse(json["dateTime"].toString()),// this line you need to edit.
"dateTime": dateTime.toIso8601String(),
Now if json["dateTime"]
this value will be null then no any issue will be occure because null value will be convert into string. by adding .toString().
Upvotes: 1