sqlite - 具有空安全性的 Sqlite Flutter
问题描述
如何在使用空安全性的同时在表中插入数据。数据未插入数据库。
这是我的代码,请帮我解决这个问题,
发布规范.yaml
sqflite: ^2.0.0+3
class TodoProvider {
Database? db;
Future open() async {
String? databasesPath = await getDatabasesPath();
String path = join(databasesPath, 'color1.db');
db = await openDatabase(path, version: 1,
onCreate: (Database db, int version) async {
await db.execute('''
create table $tableTodo (
$columnId integer primary key autoincrement,
$columnTitle text not null,
$columnDone integer not null)
''');
});
}
Future<Todo> insert(Todo todo) async {
await db?.insert(tableTodo, todo.toMap())
.then((value) {
print(value);
print('DONE');
close();
});
return todo;
}
}
解决方案
推荐阅读
- flutter - Flutter 中的 FCM 后台处理 - iOS
- regex - 用于 JSON 响应的 SED 无效命令代码
- c# - NUnit 和 NSubstitute 无法在 unittest 中正确捕获异常
- angular - 错误:超时 - 异步回调未在 5000 毫秒内调用 karma-jasmine
- python - Pygame Platformer Sprite Collisions 仅以一种方式工作
- python - 我正在通过 Python 在 excel 中过滤一些条件
- r - 创建从数据框继承的 S4 类
- javascript - 在没有 DOM 解析器的情况下解析 XML 并使用 JavaScript 在 Map 中存储值
- ios - 当我的应用播放音乐时如何停止其他应用的音乐
- button - 带有智能按钮控制台错误的 Paypal Express 结帐