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
Debugging in Python how to Diagnose and Fix Errors in your Python Code
Python Debugging - Get an essential part of the software development...
Continue readingBuilding a Command-Line Weather App with Python
In this blog, we explored the process of building a command-line wea...
Continue reading