fromPrimitives method
- Object? data
override
Called by the RestorationMixin to convert the data
previously
retrieved from toPrimitives back into an object of type T
that this
property should wrap.
The object returned by this method is passed to initWithValue to restore
the value that this property is wrapping to the value described by the
provided data
.
The method may be called multiple times throughout the life of the RestorableProperty. Whenever new restoration data has been provided to the RestorationMixin the property is registered to, either this method or createDefaultValue is called before initWithValue is invoked.
Implementation
@override
T? fromPrimitives(Object? data) {
if (data == null) {
return null;
}
if (data is String) {
for (final T allowed in values) {
if (allowed.name == data) {
return allowed;
}
}
assert(false,
'Attempted to set an unknown enum value "$data" that is not null, or '
'in the valid set of enum values for the $T type: '
'${values.map<String>((T value) => value.name).toSet()}');
}
return _defaultValue;
}