首页 > 解决方案 > 具有空安全性的 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;
  }
}

标签: sqliteflutterflutter-dependencies

解决方案


推荐阅读