Docs Menu
Docs Home
/ /
Atlas Device SDKs
/ / /

CRUD - Delete - Flutter SDK

On this page

  • Delete Objects
  • Delete a Single Object
  • Delete Multiple Objects
  • Delete All Objects of a Type

You can choose to delete a single object, multiple objects, or all objects from the database. After you delete an object, you can no longer access or modify it. If you try to use a deleted object, the SDK throws an error.

Deleting objects from the database does not delete the realm file or affect the schema. It only deletes the object instance from the database. If you want to delete the realm file itself, refer to Delete a Realm File - Flutter SDK.

The examples on this page use two object types, Person and Team.

@RealmModel()
class _Person {
@PrimaryKey()
late ObjectId id;
late String name;
late List<String> hobbies;
}
@RealmModel()
class _Team {
@PrimaryKey()
late ObjectId id;
late String name;
late List<_Person> crew;
late RealmValue eventLog;
}

Delete an object from the database by calling Realm.delete() in a write transaction block.

realm.write(() {
realm.delete(obiWan);
});

Delete multiple objects from the database by calling Realm.deleteMany() in a write transaction block.

realm.write(() {
realm.deleteMany([obiWan, quiGon]);
});

Delete all objects of a type in the database with Realm.deleteAll() in a write transaction block.

realm.write(() {
realm.deleteAll<Person>();
});

Back

Update