让我们使用此代码片段作为示例。数据模型非常简单:
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)