小编Bas*_*sam的帖子

更新 SQLite 中的字段(Flutter)

让我们使用此代码片段作为示例。数据模型非常简单:

class Dog {
  final int id;
  final String name;
  final int age;

  Dog({this.id, this.name, this.age});
}
Run Code Online (Sandbox Code Playgroud)

为了更新信息,我使用这个函数:

Future<void> updateDog(Dog dog) async {
  // Get a reference to the database.
  final db = await database;

  // Update the given Dog.
  await db.update(
    'dogs',
    dog.toMap(),
    // Ensure that the Dog has a matching id.
    where: "id = ?",
    // Pass the Dog's id as a whereArg to prevent SQL injection.
    whereArgs: [dog.id],
  );
}

await updateDog(Dog(id: 0, name: 'Fido', …
Run Code Online (Sandbox Code Playgroud)

sqlite flutter sqflite

7
推荐指数
2
解决办法
1万
查看次数

标签 统计

flutter ×1

sqflite ×1

sqlite ×1