platform<T> function

Future<T> platform<T>(
  1. {_FutureCallback<T> android,
  2. _FutureCallback<T> ios}
)

Implementation

Future<T> platform<T>(
    {_FutureCallback<T> android, _FutureCallback<T> ios}) async {
  if (android != null && Platform.isAndroid) {
    final releasePool = <Ref>{};
    final result = await android(releasePool);
    releasePool
      ..forEach((it) => PlatformFactoryAndroid.release(it))
      ..clear();
    // remove all local object from global object pool
    kNativeObjectPool.removeAll(releasePool);
    return result;
  } else if (ios != null && Platform.isIOS) {
    final releasePool = <Ref>{};
    final result = await ios(releasePool);
    releasePool
      ..forEach((it) => PlatformFactoryIOS.release(it))
      ..clear();
    // remove all local object from global object pool
    kNativeObjectPool.removeAll(releasePool);
    return result;
  } else {
    return Future.value();
  }
}