{"id":13829952,"url":"https://github.com/realm/realm-dart","last_synced_at":"2025-04-07T23:11:47.130Z","repository":{"id":37090279,"uuid":"274753366","full_name":"realm/realm-dart","owner":"realm","description":"Realm is a mobile database: a replacement for SQLite \u0026 ORMs. ","archived":false,"fork":false,"pushed_at":"2024-06-25T13:55:06.000Z","size":63970,"stargazers_count":737,"open_issues_count":109,"forks_count":78,"subscribers_count":31,"default_branch":"main","last_synced_at":"2024-06-26T09:15:12.099Z","etag":null,"topics":["cross-platform","dart","database","flutter","mobile","nosql-database","object-oriented-da","realtime-database"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/realm.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-24T19:32:54.000Z","updated_at":"2024-06-27T19:02:42.998Z","dependencies_parsed_at":"2023-02-19T11:45:52.627Z","dependency_job_id":"80d752e2-fd84-48fb-a0ba-6098540aeee1","html_url":"https://github.com/realm/realm-dart","commit_stats":{"total_commits":819,"total_committers":30,"mean_commits":27.3,"dds":0.6874236874236874,"last_synced_commit":"641956d46d512c92234991c45e8288d433e0a6bc"},"previous_names":[],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realm%2Frealm-dart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realm%2Frealm-dart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realm%2Frealm-dart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/realm%2Frealm-dart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/realm","download_url":"https://codeload.github.com/realm/realm-dart/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247744335,"owners_count":20988783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cross-platform","dart","database","flutter","mobile","nosql-database","object-oriented-da","realtime-database"],"created_at":"2024-08-04T10:00:50.971Z","updated_at":"2025-04-07T23:11:47.109Z","avatar_url":"https://github.com/realm.png","language":"Dart","funding_links":[],"categories":["\u003ca name=\"dart\"\u003e Dart"],"sub_categories":["\u003ca name=\"dotnet-libs\"\u003e\u003c/a\u003e.Net Libraries and Components"],"readme":"\u003e [!WARNING]\n\u003e We announced the deprecation of Atlas Device Sync + Realm SDKs in September 2024. For more information please see:\n\u003e - [SDK Deprecation](https://www.mongodb.com/docs/atlas/device-sdks/deprecation)\n\u003e - [Device Sync Deprecation](https://www.mongodb.com/docs/atlas/app-services/sync/device-sync-deprecation)\n\u003e\n\u003e For a version of `realm-dart` without sync features, install version 20 or see the `community` branch.\n\n\u003cpicture\u003e\n    \u003csource srcset=\"./media/logo-dark.svg\" media=\"(prefers-color-scheme: dark)\" alt=\"realm by MongoDB\"\u003e\n    \u003cimg src=\"./media/logo.svg\" alt=\"realm by MongoDB\"\u003e\n\u003c/picture\u003e\n\n[![License](https://img.shields.io/badge/License-Apache-blue.svg)](LICENSE)\n[![Realm Dart CI](https://github.com/realm/realm-dart/actions/workflows/ci.yml/badge.svg)](https://github.com/realm/realm-dart/actions/workflows/ci.yml)\n[![Coverage Status](https://coveralls.io/repos/github/realm/realm-dart/badge.svg?branch=main)](https://coveralls.io/github/realm/realm-dart?branch=main)\n\nRealm is a mobile database that runs directly inside phones, tablets or wearables.\nThis repository holds the source code for the Realm SDK for Flutter™ and Dart™.\n\n## Features\n\n* **Mobile-first:** Realm is the first database built from the ground up to run directly inside phones, tablets, and wearables.\n* **Simple:** Realm’s object-oriented data model is simple to learn, doesn’t need an ORM, and the [API](https://pub.dev/documentation/realm/latest/) lets you write less code to get apps up \u0026 running in minutes.\n* **Modern:** Realm supports latest Dart and Flutter versions and is built with sound null-safety.\n* **Fast:** Realm is faster than even raw SQLite on common operations while maintaining an extremely rich feature set.\n* **[MongoDB Atlas Device Sync](https://www.mongodb.com/docs/atlas/app-services/sync/)**: Makes it simple to keep data in sync across users, devices, and your backend in real-time. Get started for free with [a template application](https://github.com/mongodb/template-app-dart-flutter-todo) and [create the cloud backend](https://mongodb.com/realm/register?utm_medium=github_atlas_CTA\u0026utm_source=realm_dart_github).\n\n## Getting Started\n\n* Import Realm in a dart file `app.dart`\n\n    ```dart\n    import 'package:realm/realm.dart';  // import realm package\n\n    part 'app.realm.dart'; // declare a part file.\n\n    @RealmModel() // define a data model class named `_Car`.\n    class _Car {\n      late String make;\n\n      late String model;\n\n      int? kilometers = 500;\n    }\n    ```\n\n* Generate RealmObject class `Car` from data model class `_Car`.\n\n    ```\n    dart run realm generate\n    ```\n\n* Open a Realm and add some objects.\n\n    ```dart\n    var config = Configuration.local([Car.schema]);\n    var realm = Realm(config);\n\n    var car = Car(\"Tesla\", \"Model Y\", kilometers: 5);\n    realm.write(() {\n      realm.add(car);\n    });\n    ```\n\n* Query objects in Realm.\n\n    ```dart\n    var cars = realm.all\u003cCar\u003e();\n    Car myCar = cars[0];\n    print(\"My car is ${myCar.make} model ${myCar.model}\");\n\n    cars = realm.all\u003cCar\u003e().query(\"make == 'Tesla'\");\n    ```\n\n* Get stream of result changes for a query.\n\n    ```dart\n    final cars = realm.all\u003cCar\u003e().query(r'make == $0', ['Tesla']);\n    cars.changes.listen((changes) {\n      print('Inserted indexes: ${changes.inserted}');\n      print('Deleted indexes: ${changes.deleted}');\n      print('Modified indexes: ${changes.modified}');\n    });\n    realm.write(() =\u003e realm.add(Car('VW', 'Polo', kilometers: 22000)));\n    ```\n\n## Samples\n\nFor complete samples check the [Realm Flutter and Dart Samples](https://github.com/realm/realm-dart-samples).\n\n## Documentation\n\nFor API documentation go to\n * [Realm Flutter API Docs](https://pub.dev/documentation/realm/latest/)\n\n * [Realm Dart API Docs](https://pub.dev/documentation/realm_dart/latest/)\n\nUse [realm](https://pub.dev/packages/realm) package for Flutter and [realm_dart](https://pub.dev/packages/realm_dart) package for Dart applications.\n\nFor complete documentation of the SDKs, go to the [Realm SDK documentation](https://www.mongodb.com/docs/atlas/device-sdks/sdk/flutter/).\n\nIf you are using the Realm SDK for the first time, refer to the [Quick Start documentation](https://www.mongodb.com/docs/realm/sdk/flutter/quick-start/).\n\nTo learn more about using Realm with Atlas App Services and Device Sync, refer to the following Realm SDK documentation:\n\n- [App Services Overview](https://www.mongodb.com/docs/realm/sdk/flutter/app-services/)\n- [Device Sync Overview](https://www.mongodb.com/docs/realm/sdk/flutter/sync/)\n\n# Realm Flutter SDK\n\nRealm Flutter package is published to [realm](https://pub.dev/packages/realm).\n\n## Environment setup for Realm Flutter\n\n* Realm Flutter supports the platforms iOS, Android, Windows, MacOS and Linux.\n* Flutter 3.10.2 or newer.\n* For Flutter Desktop environment setup, see [Desktop support for Flutter](https://docs.flutter.dev/desktop).\n* Cocoapods v1.11 or newer.\n* CMake 3.21 or newer.\n\n## Usage\n\n**The full contents of `catalog.dart` is listed [after the usage](https://github.com/realm/realm-dart#full-contents-of-catalogdart)**\n\n* Add `realm` package to a Flutter application.\n\n    ```\n    flutter pub add realm\n    ```\n* For running Flutter widget and unit tests run the following command to install the required native binaries.\n\n    ```\n    dart run realm install\n    ```\n\n* Import Realm in a dart file (ex. `catalog.dart`).\n\n    ```dart\n    import 'package:realm/realm.dart';\n    ```\n\n* Declare a part file `catalog.realm.dart` in the begining of the `catalog.dart` dart file after all imports.\n\n    ```dart\n    import 'dart:io';\n\n    part 'catalog.realm.dart';\n    ```\n\n* Create a data model class.\n\n    It should start with an underscore `_Item` and be annotated with `@RealmModel()`\n\n    ```dart\n    @RealmModel()\n    class _Item {\n        @PrimaryKey()\n        late int id;\n\n        late String name;\n\n        int price = 42;\n    }\n    ```\n\n* Generate RealmObject class `Item` from data model class `_Item`.\n\n    _*On Flutter use `dart run realm` to run `realm` package commands*_\n\n    ```\n    dart run realm generate\n    ```\n    A new file `catalog.realm.dart` will be created next to the `catalog.dart`.\n\n    _*The generated file should be committed to source control_\n\n* Use the RealmObject class `Item` with Realm.\n\n    ```dart\n    // Create a Configuration object\n    var config = Configuration.local([Item.schema]);\n\n    // Opean a Realm\n    var realm = Realm(config);\n\n    var myItem = Item(0, 'Pen', price: 4);\n\n    // Open a write transaction\n    realm.write(() {\n        realm.add(myItem);\n        var item = realm.add(Item(1, 'Pencil')..price = 20);\n    });\n\n    // Objects `myItem` and `item` are now managed and persisted in the realm\n\n    // Read object properties from realm\n    print(myItem.name);\n    print(myItem.price);\n\n    // Update object properties\n    realm.write(() {\n        myItem.price = 20;\n        myItem.name = \"Special Pencil\";\n    });\n\n    // Get objects from the realm\n\n    // Get all objects of type\n    var items = realm.all\u003cItem\u003e();\n\n    // Get object by index\n    var item = items[1];\n\n    // Get object by primary key\n    var itemByKey = realm.find\u003cItem\u003e(0);\n\n    // Filter and sort object\n    var objects = realm.query\u003cItem\u003e(\"name == 'Special Pencil'\");\n    var name = 'Pen';\n    objects = realm.query\u003cItem\u003e(r'name == $0', [name]);\n\n    // Close the realm\n    realm.close();\n    ```\n\n## Full contents of `catalog.dart`\n\n```dart\nimport 'package:realm/realm.dart';\n\npart 'catalog.realm.dart';\n\n@RealmModel()\nclass _Item {\n    @PrimaryKey()\n    late int id;\n\n    late String name;\n\n    int price = 42;\n}\n\n// Create a Configuration object\nvar config = Configuration.local([Item.schema]);\n\n// Open a Realm\nvar realm = Realm(config);\n\nvar myItem = Item(0, 'Pen', price: 4);\n\n// Open a write transaction\nrealm.write(() {\n    realm.add(myItem);\n    var item = realm.add(Item(1, 'Pencil')..price = 20);\n});\n\n// Objects `myItem` and `item` are now managed and persisted in the realm\n\n// Read object properties from realm\nprint(myItem.name);\nprint(myItem.price);\n\n// Update object properties\nrealm.write(() {\n    myItem.price = 20;\n    myItem.name = \"Special Pencil\";\n});\n\n// Get objects from the realm\n\n// Get all objects of type\nvar items = realm.all\u003cItem\u003e();\n\n// Get object by index\nvar item = items[1];\n\n// Get object by primary key\nvar itemByKey = realm.find\u003cItem\u003e(0);\n\n// Filter and sort object\nvar objects = realm.query\u003cItem\u003e(\"name == 'Special Pencil'\");\nvar name = 'Pen';\nobjects = realm.query\u003cItem\u003e(r'name == $0', [name]);\n\n// Close the realm\nrealm.close();\n```\n\n# Realm Dart Standalone SDK\n\nRealm Dart package is published to [realm_dart](https://pub.dev/packages/realm_dart).\n\n## Environment setup for Realm Dart\n\n* Realm Dart supports the platforms Windows, Mac and Linux.\n* Dart SDK 3.0.2 or newer.\n\n## Usage\n\n* Add `realm_dart` package to a Dart application.\n\n    ```\n    dart pub add realm_dart\n    ```\n\n* Install the `realm_dart` package into the application. This downloads and copies the required native binaries to the app directory.\n\n    ```\n    dart run realm_dart install\n    ```\n\n* Import realm_dart in a dart file (ex. `catalog.dart`).\n\n    ```dart\n    import 'package:realm_dart/realm.dart';\n    ```\n\n* To generate RealmObject classes with realm_dart use this command.\n\n    _*On Dart use `dart run realm_dart` to run `realm_dart` package commands*_\n\n    ```\n    dart run realm_dart generate\n    ```\n    A new file `catalog.realm.dart` will be created next to the `catalog.dart`.\n\n    _*The generated file should be committed to source control_\n\n* The usage of the Realm Dart SDK is the same like the Realm Flutter above.\n\n# Sync data with Realm Flutter and Dart using Device Sync\n\nThis section is about how to use the Realm with [Device Sync](https://www.mongodb.com/docs/realm/sdk/flutter/sync/) and how to connect to [Atlas App Services](https://www.mongodb.com/docs/realm/sdk/flutter/app-services/).\n\n### I. Set up Atlas App Services\n  1. Create an account on [cloud.mongodb.com](https://cloud.mongodb.com). Follow the instructions: [Register a new Atlas Account](https://www.mongodb.com/docs/atlas/tutorial/create-atlas-account/#register-a-new-service-account).\n  1. Create a new App following the instructions here: [Create an App with Atlas App Services UI](https://www.mongodb.com/docs/atlas/app-services/manage-apps/create/create-with-realm-ui).\n  1. Read [Authentication Providers](https://www.mongodb.com/docs/atlas/app-services/authentication/providers/) to see how to configure the appropriate authentication provider type.\n  1. Go to the **Device Sync** menu and [Enable Flexible Sync](https://www.mongodb.com/docs/atlas/app-services/sync/configure/enable-sync/#enable-flexible-sync).\n  1. [Find and Copy the App ID](https://www.mongodb.com/docs/atlas/app-services/reference/find-your-project-or-app-id/) of your new application.\n\n### II. Use Device Sync with the Realm\n\n1. Initialize the App Services `App` client and authenticate a user.\n\n   ``` dart\n   String appId = \"\u003cAtlas App ID\u003e\";\n   final appConfig = AppConfiguration(appId);\n   final app = App(appConfig);\n   final user = await app.logIn(Credentials.anonymous());\n   ```\n1. Open a synced realm.\n\n   ``` dart\n   final config = Configuration.flexibleSync(user, [Task.schema]);\n   final realm = Realm(config);\n   ```\n\n1. Add a sync subscription and write data.\n\n   Only data matching the query in the subscription will be synced to the server and only data matching the subscription will be downloaded to the local device realm file.\n\n   ``` dart\n   realm.subscriptions.update((mutableSubscriptions) {\n   mutableSubscriptions.add(realm.query\u003cTask\u003e(r'status == $0 AND progressMinutes == $1', [\"completed\", 100]));\n   });\n   await realm.subscriptions.waitForSynchronization();\n   realm.write(() {\n     realm.add(Task(ObjectId(), \"Send an email\", \"completed\", 4));\n     realm.add(Task(ObjectId(), \"Create a meeting\", \"completed\", 100));\n     realm.add(Task(ObjectId(), \"Call the manager\", \"init\", 2));\n   });\n   realm.close();\n   ```\n\nTo learn more about how to sync data with Realm using Device Sync, refer to the [Quick Start with Sync documentation](https://www.mongodb.com/docs/realm/sdk/flutter/quick-start/#sync-realm-with-mongodb-atlas).\n\n# Building the source\n\nSee [CONTRIBUTING.md](https://github.com/realm/realm-dart/blob/main/CONTRIBUTING.md#building-the-source) for instructions about building the source.\n\n# Code of Conduct\n\nThis project adheres to the [MongoDB Code of Conduct](https://www.mongodb.com/community-code-of-conduct).\nBy participating, you are expected to uphold this code. Please report\nunacceptable behavior to [community-conduct@mongodb.com](mailto:community-conduct@mongodb.com).\n\n# License\n\nRealm Flutter and Dart SDKs and [Realm Core](https://github.com/realm/realm-core) are published under the Apache License 2.0.\n\n##### The \"Dart\" name and logo and the \"Flutter\" name and logo are trademarks owned by Google.\n\n\u003cimg style=\"width: 0px; height: 0px;\" src=\"https://3eaz4mshcd.execute-api.us-east-1.amazonaws.com/prod?s=https://github.com/realm/realm-dart#README.md\"\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frealm%2Frealm-dart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frealm%2Frealm-dart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frealm%2Frealm-dart/lists"}