When trying to read json files generated with golangs json package in Dart / Flutter I noticed that parsing dates produce an error:
FormatException: Invalid date format
An example is the following json generated on the Go server:
{
...
"dateCreated": "2018-09-29T19:51:57.4139787-07:00",
...
}
I am using the code generation approach for json (de-)serialization to avoid writing all the boiler plate code. The json_serializable package is a standard package available for this purpose. So my code looks like the following:
@JsonSerializable()
class MyObj {
DateTime dateCreated;
MyObj( this.dateCreated);
factory MyObj.fromJson(Map<String, dynamic> json) => _$MyObjFromJson(json);
Map<String, dynamic> toJson() => _$MyObjToJson(this);
}