Open a Synced Realm - Flutter SDK
This page describes how to open a synced realm using Atlas Device Sync. To learn how to open and configure non-synced realms, see Open and Close a Realm.
Before You Begin
Before you open a realm with Flexible Sync in a Flutter application:
- Configure Flexible Sync on the backend. You must configure Flexible Sync in the backend before you can use it with your client application.
- Initialize the App client.
- Authenticate a user in your client project.
Open a Synced Realm
To open a synced realm, pass a logged in user, a list of Realm object schemas, and additional optional parameters to the Configuration.flexibleSync() constructor. Then, pass the configuration to Realm() to open an instance of the realm.
User currentUser = await app.logIn(credentials); Configuration config = Configuration.flexibleSync( currentUser, [Tricycle.schema], path: 'flex.realm'); Realm realm = Realm(config);
Once you open a synced realm, configure and manage the sync session.
Configure a Realm
For more information on additional configuration options, refer to Configure a Realm.
Close a Realm
Once you've finished working with a synced realm, close it to prevent memory leaks.
realm.close();
Further Reading
- Manage a Sync Session: Learn how to add, modify, and remove sync subscriptions once you've opened a synced realm.