realm_generator 0.2.1+alpha copy "realm_generator: ^0.2.1+alpha" to clipboard
realm_generator: ^0.2.1+alpha copied to clipboard

outdated

Generates RealmObject classes from Realm data model classes. This package is part of the official Realm Flutter and Realm Dart SDKs.

Realm

License

This project is in the Alpha stage. All API's might change without warning and no guarantees are given about stability. Do not use it in production.

Description #

Dart code generator that generates RealmObject classes based on Realm data model classes using naming conventions.

This package is part of the official Realm Flutter and Realm Dart SDKs https://github.com/realm/realm-dart

Usage #

  • Add a dependency to realm package or realm_dart package to your application.

To generate RealmObjects

  • Run flutter pub run realm generate for Flutter projects

  • Run dart run realm_dart generate for Dart projects

Conventions #

  • Every Dart class annotated with @RealmModel() and named with an underscore like _ClassName, is considered a Realm data model class and the code generator will generate a RealmObject class that can be used with Realm Flutter™ and Realm Dart™.

  • The Dart file containg Realm schema classes needs to have a part defintion name in the format

    part "filename.g.dart".

    For example: In file cars.dart there should be a part definition part "cars.g.dart"

  • The underscore in the class name is requried. class _Car.

  • Every field that references another RealmObject must use the schema class name of that RealmObject. For example:

    class _Car {
      late _Car secondCar;
    }
    
  • The generator will infer the Realm type from the Dart type of every property of the class.

Example #

Filename: cars.dart

part "cars.g.dart"

@RealmModel()
class _Car {
  late String make; //required field
  late String? model; //optional field
  String kilometers = 500; //default value
  late _Car? secondCar; //Object relationship 1:1
  final List<_Car> allOtherCars; //Object relationship 1:Many
}

Debugging #

  • On first use .dart_tool/build/entrypoint/build.dart needs to be generated with pub run build_runer build

  • Use a terminal to launch a debuggee with command

    dart --observe --pause-isolates-on-start  --enable-vm-service:5858/127.0.0.1  --disable-service-auth-codes .dart_tool/build/entrypoint/build.dart build
    
The "Dart" name and logo and the "Flutter" name and logo are trademarks owned by Google.
4
likes
0
pub points
62%
popularity

Publisher

verified publisherrealm.io

Generates RealmObject classes from Realm data model classes. This package is part of the official Realm Flutter and Realm Dart SDKs.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

analyzer, build, build_resolvers, dart_style, realm_common, source_gen, source_span

More

Packages that depend on realm_generator