Skip to content

Commit

Permalink
Small corrections and merging in v2 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
cbullinger committed Mar 21, 2024
1 parent eda66e8 commit 33435d5
Show file tree
Hide file tree
Showing 16 changed files with 491 additions and 419 deletions.
38 changes: 26 additions & 12 deletions examples/dart/test/data_types_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ part 'data_types_test.realm.dart'; // :remove:
// part 'car.realm.dart';
// :uncomment-end:

@RealmModel()
class _Car {
@PrimaryKey()
late ObjectId id;

String? licensePlate;
bool isElectric = false;
double milesDriven = 0;
late List<String> attributes;
late _Person? owner;
}

// :snippet-start: embedded-object-model
// The generated `Address` class is an embedded object.
@RealmModel(ObjectType.embeddedObject)
Expand All @@ -35,17 +47,6 @@ class _Person {
}

// :snippet-end:
@RealmModel()
class _Car {
@PrimaryKey()
late ObjectId id;

String? licensePlate;
bool isElectric = false;
double milesDriven = 0;
late List<String> attributes;
late _Person? owner;
}
// :snippet-end:

// :snippet-start: uuid-model
Expand All @@ -71,6 +72,7 @@ class _RealmValueExample {
@Indexed()
late RealmValue singleAnyValue;
late List<RealmValue> listOfMixedAnyValues;
late Set<RealmValue> setOfMixedAnyValues;
late Map<String, RealmValue> mapOfMixedAnyValues;
}

Expand Down Expand Up @@ -173,9 +175,18 @@ main() {
final realm = Realm(Configuration.local([RealmValueExample.schema]));

realm.write(() {
// Use 'RealmValue.from()' to set values
var anyValue = realm.add(RealmValueExample(
// Add a single `RealmValue` value
singleAnyValue: RealmValue.from(1),
// Add a list of `RealmValue` values
listOfMixedAnyValues: [Uuid.v4(), 'abc', 123].map(RealmValue.from),
// Add a set of `RealmValue` values
setOfMixedAnyValues: {
RealmValue.from('abc'),
RealmValue.from('def')
},
// Add a map of string keys and `RealmValue` values
mapOfMixedAnyValues: {
'1': RealmValue.from(123),
'2': RealmValue.from('abc')
Expand All @@ -185,16 +196,19 @@ main() {
var anyValueNull = realm.add(RealmValueExample(
singleAnyValue: RealmValue.nullValue(),
listOfMixedAnyValues: [null, null].map(RealmValue.from),
setOfMixedAnyValues: {RealmValue.nullValue()},
mapOfMixedAnyValues: {'null': RealmValue.nullValue()}));

// :remove-start:
expect(anyValue.singleAnyValue.type, RealmValueType.int);
expect(anyValue.listOfMixedAnyValues[1].value.toString(), 'abc');
expect(anyValue.setOfMixedAnyValues.first.value, 'abc');
expect(
anyValue.mapOfMixedAnyValues.containsValue(RealmValue.from('abc')),
true);
expect(anyValueNull.singleAnyValue.value, null);
expect(anyValueNull.listOfMixedAnyValues[0].value, null);
expect(anyValueNull.setOfMixedAnyValues.first.value, null);
expect(anyValueNull.mapOfMixedAnyValues.containsValue(null), true);
});
// :remove-end:
Expand Down Expand Up @@ -224,7 +238,7 @@ main() {
final data = realm.all<RealmValueExample>();
for (var obj in data) {
final anyValue = obj.singleAnyValue;
// Access the RealmValue.type property
// Access the RealmValue.type property
switch (anyValue.type) {
// Work with the returned RealmValueType enums
case RealmValueType.int:
Expand Down
Loading

0 comments on commit 33435d5

Please sign in to comment.