Docs Menu
Docs Home
/ /
Atlas Device SDKs
/
/

Quick Start with Flutter

On this page

  • Install the SDK
  • Import the SDK
  • Define Your Object Model
  • Create a Model Class
  • Generate an SDK Object Class
  • Watch for Changes to the Model (Optional)
  • Perform CRUD Operations and More

This quick start demonstrates how to use Atlas Device SDK with Flutter in a Flutter application.

Tip

Flutter Project or Standalone Dart Project?

This quick start contains information for using the SDK in a Flutter project. The package that you import and the way you create object models differs when using the SDK in a standalone Dart project. For a quick start using a standalone Dart project, refer to Quick Start.

Install the realm package for use in Flutter applications. For more information about installing the SDK in a Flutter project, refer to Install Atlas Device SDK.

Import the realm package into any files where you use it.

ExampleFile.dart
import 'package:realm/realm.dart';

Your application's data model defines the structure of data stored within the database. You can define your application's data model via Dart classes in your application code with an SDK object schema. You then have to generate the RealmObjectBase class that's used within your application.

For more information, refer to Define an Object Model.

1

Add an SDK model class. Give your class a private name (starting with _), such as a file car.dart with a class _Car.

car.dart
import 'package:realm/realm.dart';
part 'car.realm.dart';
@RealmModel()
class _Car {
@PrimaryKey()
late ObjectId id;
late String make;
late String? model;
late int? miles;
}
2

Generate a RealmObject class Car from the data model class _Car:

dart run realm generate

Running this creates a Car class in a car.realm.dart file located in the directory where you defined the model class. This Car class is public and part of the same library as the _Car data model class. The generated Car class is what's used throughout your application.

3

You can watch your data model class to generate a new Car class whenever there's a change to _Car:

dart run realm generate --watch

Installing the library and the commands to generate the models are specific to using the SDK with a Flutter project or a standalone Dart project. But all the other operations, from reading and writing data to syncing data across devices, are the same for a Flutter or standalone Dart project.

To learn more about performing these operations, refer to the main Quick Start. Shared content starts with the Open a Database section.

← 
 →