ProtoGoogleValue.fromDynamic constructor
ProtoGoogleValue.fromDynamic(
- Object? value
Implementation
factory ProtoGoogleValue.fromDynamic(Object? value) {
if (value == null) {
return const ProtoGoogleValue(nullValue: ProtoGoogleNullValue.nullValue);
}
if (value is bool) return ProtoGoogleValue(boolValue: value);
if (value is num) return ProtoGoogleValue(numberValue: value.toDouble());
if (value is String) return ProtoGoogleValue(stringValue: value);
if (value is List) {
return ProtoGoogleValue(
listValue: ProtoGoogleListValue(
values: [for (final e in value) ProtoGoogleValue.fromDynamic(e)],
),
);
}
if (value is Map) {
return ProtoGoogleValue(
structValue: ProtoGoogleStruct.fromJson(
(value).cast<String, dynamic>(),
),
);
}
throw BuError(
DefaultErrorType.unsupported,
"Unsupported google.protobuf.Value: $value.",
);
}