List of object types with object count in realm standalone db

Hello, I am new to Realm, using it as standalone database in flutter app. How to get list of Objects Types with Count of each. Ex: Cars 22, Items 0, Users 20.

You can query objects of a type with the Realm.all<T>() method - example here: Read/Query All Objects.

That returns a RealmResults collection, which has a length property that can give you the count of objects: RealmResults.length API reference

So you would need to perform the Realm.all<T>() call for each object type whose count you want to retrieve, and then access the .length property each time to get the count.

Thank you for your reply. That is correct but what if want to get what is available in database dynamically without specifying the object type explicitly . I tried to loop through existing objects types after getting them from the realm.config but is not working.

This is the code, loop is working fine, it returns all schema objects, but when I pass each object as it gives error

// get all object types from schema and loop through them
for (final schemaObject in _database.realm.config.schemaObjects) {
  // print number of objects created from this type
  print(_database.realm.all<**schemaObject**>().length);
}

the error “Error: ‘schemaObject’ isn’t a type.”