1 | initial version |
To save a Boolean variable in SQFLite, you can first convert the Boolean value to an integer (0 or 1) using a ternary operator. For example:
bool myBool = true;
int myInt = myBool ? 1 : 0;
Then, you can use the insert
or update
method from SQFLite to store the integer value in a database column with the appropriate data type, such as INTEGER
or BOOLEAN
. For example:
await db.insert('myTable', {'myBooleanColumn': myInt});
To retrieve the Boolean value from the database, you can read the integer value from the column and convert it back to a Boolean using another ternary operator. For example:
int myIntFromDb = await db.query('myTable', columns: ['myBooleanColumn']);
bool myBoolFromDb = myIntFromDb == 1 ? true : false;