This is a todo list app which uses a database. I am using a boolean variable isDone to mark a task as complete but when i add a new task, i get the error 'String' is not a subtype of type 'bool'. I want to change the value of isDone to string but i am unsure on where exactly i can type the .toString() line.
Tried using the solution for similar errors (int, bool, future is not a subtype of string, bool, etc.) but could'nt solve it because those errors were application specific.
database code :
//This is the database
String _itemName;
String _dateCreated;
int _id;
bool _isDone;
TodoItem(this._itemName, this._dateCreated, this._isDone);
TodoItem.map(dynamic obj) {
this._itemName = obj["itemName"];
this._dateCreated = obj["dateCreated"];
this._id = obj["id"];
this._isDone = obj["isDone"];
}
String get itemName => _itemName;
String get dateCreated => _dateCreated;
int get id => _id;
bool get isDone => _isDone;
Map<String, dynamic> toMap() {
var map = new Map<String, dynamic>();
map["itemName"] = _itemName;
map["dateCreated"] = _dateCreated;
map["isDone"] = _isDone;
if (_id != null) {
map["id"] = _id;
}
return map;
}
TodoItem.fromMap(Map<String, dynamic> map) {
this._itemName = map["itemName"];
this._dateCreated = map["dateCreated"];
this._id = map["id"];
this._isDone = map["isDone"];
}
database create, update functions :
NOTE: the update function is only supposed to change the value of isDone
Future<bool> updateItem(TodoItem item) async {
var dbClient = await db;
int res = await dbClient.update("id", item.toMap(),
where: "id = ?", whereArgs: <bool>[item.isDone]);
return res > 0 ? true : false;
}
Future<int> saveItem(TodoItem item) async {
var dbClient = await db;
int res = await dbClient.insert("$tableName", item.toMap());
print(res.toString());
return res;
}