Open & Close a Realm - Flutter SDK
On this page
Open a Realm
Use the Configuration class to control the specifics of the realm you would like to open, including schema.
Pass your configuration to the Realm constructor to generate an instance of that realm:
var config = Configuration([Car.schema]); var realm = Realm(config);
You can now use that realm instance to work with objects in the database.
Open a Read-Only Realm
You can open an existing realm in read-only mode. To open a read-only realm,
add readOnly: true
to your Configuration
object.
You can only open existing realms in read-only mode. If you try to write to a read-only realm, it throws an error.
var config = Configuration([Car.schema], readOnly: true); realm = Realm(config);
Open an In-Memory Realm
To create a realm that runs entirely in memory without being written to a file,
add inMemory: true
to your Configuration
object.
In-memory realms cannot also be read-only.
var config = Configuration([Car.schema], inMemory: true); var realm = Realm(config);
Set Custom FIFO Special Files
Set a value for Realm's FIFO special files location.
Opening a realm creates a number of lightweight FIFO special files
that coordinate access to the realm across threads and processes.
If the realm file is in a location that doesn't allow for the creation of
FIFO special files (such as FAT32 filesystems), then the realm cannot be opened.
In this case, Realm needs a different location to store these files.
Add fifoFilesFallbackPath: <Your Custom FIFO File Path>
to your Configuration
object.
This property is ignored if the directory for the realm file allows FIFO special files.
var config = Configuration([Car.schema], fifoFilesFallbackPath: "./fifo_folder"); var realm = Realm(config);
Close a Realm
Once you've finished working with a realm, close it to prevent memory leaks.
realm.close();