在我的 Flutter 项目中,我有一个类 Category 女巫,包含一个 String、Icon、IconData 和两种颜色:(我不想存储图标,因为我可以用我的 iconData 重新创建它)
class Category {
Icon icon;
IconData iconData;
Color color;
Color backgroundcolor;
String name;
[...]
Map<String, dynamic> toMap() {
return {
'iconData': iconData,
'color': color,
'backgroundcolor': backgroundcolor,
'name': name
};
}
对于我的项目,我导入了 sqflite 数据库,创建了一个表类别(使用“CREATE TABLE 类别(名称 TEXT,iconData BLOB,color BLOB,backgroundcolor BLOB”)),现在想在我的数据库中插入一个类别,其中包含以下内容:
Future<void> insertCategory(Category category) async {
// get reference to the database
final Database db = await database;
// insert new category
await db.insert('categories', category.toMap(),
conflictAlgorithm: ConflictAlgorithm.replace);
print("Category inserted.");
}
但是当我尝试插入一个类别时,我得到一个参数错误(无效的参数:'IconData'的实例),我无法弄清楚问题出在哪里。