packObject<T> function
T
packObject<T>(
- dynamic receiver,
- T factory()
Wrap native object into specified type instance T is the target type receiver is the native object factory is the constructor of target type
Implementation
T packObject<T>(dynamic receiver, T Function() factory) {
if (isPrimitiveValue(receiver)) {
return receiver as T;
}
final instance = factory(); // Create instance through factory method
if (instance is PackClass) {
(instance as PackClass).updateInstance(receiver);
} else if (instance is NativeObserverClass) {
(instance as NativeObserverClass).updateInstance(receiver);
} else if (instance is NativeClass) {
final map = Map<String, dynamic>.from(receiver);
(instance as NativeClass).updateResource(NativeResource(
instanceId: map['_instanceId'],
));
}
return instance;
}