fromCodecValue static method Null safety
- dynamic value
Constructs a value from an arbitrary platform value.
Supports primitive values from types bool, num, and String, as well as the null inhabitant. All other
primitives will be converted to ofNull. Supports complex values from List, where each element will be
converted as a codec value, and Map with String keys, where the values will be converted as codec values.
Implementation
static LDValue fromCodecValue(dynamic value) {
if (value is bool) {
return ofBool(value);
}
if (value is num) {
return ofNum(value);
}
if (value is String) {
return ofString(value);
}
if (value is List) {
var builder = buildArray();
value.forEach((element) {
builder.addValue(fromCodecValue(element));
});
return builder.build();
}
if (value is Map) {
var builder = buildObject();
value.forEach((key, value) {
builder.addValue(key, fromCodecValue(value));
});
return builder.build();
}
return ofNull();
}