safeEncode method
encode method with toEncodable
to correctly encode a DateTime object.
Implementation
String safeEncode(Object obj) {
return json.encode(obj, toEncodable: (value) {
if (value is DateTime) return value.toIso8601String();
try {
return value.toJson();
} catch (e) {
return null;
}
});
}