5 Jan 2025
I/flutter (14571): Invalid argument 2025-01-04 07:53:00.000 with type DateTime.
If you are getting error like this then follow below steps:
I/flutter (14571): Invalid argument 2025-01-04 12:53:00.000 with type DateTime.
I/flutter (14571): Only num, String and Uint8List are supported. See https://github.com/tekartik/sqflite/blob/master/sqflite/doc/supported_types.md for details
The error message indicates that you're trying to store a DateTime
object in an SQLite database using the sqflite
package, but sqflite
only supports certain types: num
, String
, and Uint8List
. DateTime
is not directly supported.
Solution
Inside toJson() method or before inserting data in database convert the DateTime
object to a string using the toIso8601String()
method:
// before (assuming: MyCreateDate datetime null)
// ... other fields
"MyCreateDate": MyCreateDate,
// ... other fields
// now
// before (assuming: MyCreateDate datetime null)
// ... other fields
"MyCreateDate": MyCreateDate?.toIso8601String(),
// ... other fields
You may also like
In Android or Flutter some cases wav sound not playing
In Android or Flutter some cases wav sound not playing
Continue readingFlutter Multilingual implemention and language file generation
Flutter Multilingual implemention and language file generation
Continue reading