RealmValue class

A type that can represent any valid realm data type, except embedded objects.

You can use RealmValue to declare fields on realm models, in which case it must be non-nullable, but it can wrap a null-value. List of RealmValue (List<RealmValue>) are also legal.

RealmValue fields can be Indexed

@RealmModel()
class _AnythingGoes {
  @Indexed()
  late RealmValue any;
  late List<RealmValue> manyAny;
}

void main() {
  final realm = Realm(Configuration.local([AnythingGoes.schema]));
  realm.write(() {
    final something = realm.add(AnythingGoes(any: RealmValue.string('text')));
    something.manyAny.addAll([
      null,
      true,
      'text',
      42,
      3.14,
    ].map(RealmValue.from));
  });
}

Constructors

RealmValue.binary(Uint8List binary)
const
RealmValue.bool(bool b)
const
RealmValue.dateTime(DateTime timestamp)
const
RealmValue.decimal128(Decimal128 decimal)
const
RealmValue.double(double d)
const
RealmValue.from(Object? object)
Constructs a RealmValue from an arbitrary object. Collections will be converted recursively as long as all their values are compatible.
factory
RealmValue.fromJson(String json)
Constructs a RealmValue from a valid json string. The json object must contain only values that are supported by RealmValue.
factory
RealmValue.int(int i)
const
RealmValue.list(List<RealmValue> list)
const
RealmValue.map(Map<String, RealmValue> map)
const
RealmValue.nullValue()
const
RealmValue.objectId(ObjectId id)
const
RealmValue.realmObject(RealmObjectMarker o)
const
RealmValue.string(String text)
const
RealmValue.uuid(Uuid uuid)
const

Properties

hashCode int
The hash code for this object.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
type RealmValueType
final
value Object?
final

Methods

as<T>() → T
Casts value to T. An exception will be thrown if the value is not convertible to T.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
override