wrapNativeReturnValue method
Wraps a native return value from a bridged call in a BridgedInstance if a bridge exists, otherwise returns the value as-is.
This is needed when bridged static getters or methods return instances
of private subclasses (e.g., Curves.linear returns _Linear which
extends Curve). The private class instance needs to be wrapped using
the public superclass bridge.
Implementation
Object? wrapNativeReturnValue(Object? nativeValue) {
if (nativeValue == null ||
nativeValue is String ||
nativeValue is num ||
nativeValue is bool) {
return nativeValue;
}
if (nativeValue is BridgedInstance) {
return nativeValue;
}
if (nativeValue is List) {
return nativeValue.map(wrapNativeReturnValue).toList();
}
if (nativeValue is Map) {
return nativeValue.map(
(key, value) =>
MapEntry(wrapNativeReturnValue(key), wrapNativeReturnValue(value)),
);
}
// Try to find a bridge for this native value
final result = toBridgedInstance(nativeValue);
if (result.$2) {
return result.$1;
}
// No bridge found, return the value as-is
return nativeValue;
}