-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
packages/realm_generator/test/good_test_data/all_named_ctor.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import 'package:realm_common/realm_common.dart'; | ||
|
||
part 'all_named_ctor.realm.dart'; | ||
|
||
const config = GeneratorConfig(ctorStyle: CtorStyle.allNamed); | ||
const realmModel = RealmModel.using(baseType: ObjectType.realmObject, generatorConfig: config); | ||
|
||
@realmModel | ||
class _Person { | ||
late String name; | ||
int age = 42; | ||
} |
82 changes: 82 additions & 0 deletions
82
packages/realm_generator/test/good_test_data/all_named_ctor.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// GENERATED CODE - DO NOT MODIFY BY HAND | ||
|
||
part of 'all_named_ctor.dart'; | ||
|
||
// ************************************************************************** | ||
// RealmObjectGenerator | ||
// ************************************************************************** | ||
|
||
// ignore_for_file: type=lint | ||
class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { | ||
static var _defaultsSet = false; | ||
|
||
Person({ | ||
required String name, | ||
int age = 42, | ||
}) { | ||
if (!_defaultsSet) { | ||
_defaultsSet = RealmObjectBase.setDefaults<Person>({ | ||
'age': 42, | ||
}); | ||
} | ||
RealmObjectBase.set(this, 'name', name); | ||
RealmObjectBase.set(this, 'age', age); | ||
} | ||
|
||
Person._(); | ||
|
||
@override | ||
String get name => RealmObjectBase.get<String>(this, 'name') as String; | ||
@override | ||
set name(String value) => RealmObjectBase.set(this, 'name', value); | ||
|
||
@override | ||
int get age => RealmObjectBase.get<int>(this, 'age') as int; | ||
@override | ||
set age(int value) => RealmObjectBase.set(this, 'age', value); | ||
|
||
@override | ||
Stream<RealmObjectChanges<Person>> get changes => | ||
RealmObjectBase.getChanges<Person>(this); | ||
|
||
@override | ||
Stream<RealmObjectChanges<Person>> changesFor([List<String>? keyPaths]) => | ||
RealmObjectBase.getChangesFor<Person>(this, keyPaths); | ||
|
||
@override | ||
Person freeze() => RealmObjectBase.freezeObject<Person>(this); | ||
|
||
EJsonValue toEJson() { | ||
return <String, dynamic>{ | ||
'name': name.toEJson(), | ||
'age': age.toEJson(), | ||
}; | ||
} | ||
|
||
static EJsonValue _toEJson(Person value) => value.toEJson(); | ||
static Person _fromEJson(EJsonValue ejson) { | ||
return switch (ejson) { | ||
{ | ||
'name': EJsonValue name, | ||
'age': EJsonValue age, | ||
} => | ||
Person( | ||
name: fromEJson(name), | ||
age: fromEJson(age), | ||
), | ||
_ => raiseInvalidEJson(ejson), | ||
}; | ||
} | ||
|
||
static final schema = () { | ||
RealmObjectBase.registerFactory(Person._); | ||
register(_toEJson, _fromEJson); | ||
return SchemaObject(ObjectType.realmObject, Person, 'Person', [ | ||
SchemaProperty('name', RealmPropertyType.string), | ||
SchemaProperty('age', RealmPropertyType.int), | ||
]); | ||
}(); | ||
|
||
@override | ||
SchemaObject get objectSchema => RealmObjectBase.getSchema(this) ?? schema; | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/realm_generator/test/good_test_data/all_named_ctor.realm.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
part of 'all_named_ctor.dart'; |