How to convert DateTime
object to json? It throws Converting object to an encodable object failed.
, so is this a bug or it\'s just dart
you are encoding object(DateTime) into other encodable object JSON.encode(DateTime.Now()) which is not possible in dart programming.
So, convert it to dart supported Date to String conversion that is : add : .toIso8601String() at the end
JSON.encode(DateTime.Now().toIso8601String()),this resolves your error. // i am taking DateTime.Now() just for example.