I create a TABLE
with some columns and everything's ok until I tried to insert a new DATETIME column:
_onCreate(Database db, int version) async {
await db.
execute("CREATE TABLE $TABLE ($ID INTEGER PRIMARY KEY, $NAME TEXT, $COLOUR
TEXT, $BREED TEXT, $BIRTH DATETIME)");
}
My Model Class to store is:
class Pet {
int id;
String name;
DateTime birth;
String breed;
String colour;
Pet({this.id, this.name, this.birth, this.colour, this.breed});
}
In the controller, I tried to store a new instance of Pet
, instantiating a new variable DateTime _date = new DateTime.now();
and saving all in
Pet newPet = Pet(
id: null,
name: _name,
colour: _colour,
breed: _breed,
birth: _date
);
But when I insert in the database I receive:
Unhandled Exception: Invalid argument: Instance of 'DateTime'