initNativeView method

void initNativeView()

Implementation

void initNativeView() {
  if (nativeView != null) {
    onPlatformViewCreated(viewId);
    return;
  }
  if (Platform.isAndroid) {
    if (renderType == RenderType.HybridComposition) {
      TTFLogger.i('TTVideoPlayerView', 'use HybridComposition');
      nativeView = PlatformViewLink(
        viewType: viewType,
        surfaceFactory: (context, controller) {
          return AndroidViewSurface(
            controller: controller as AndroidViewController,
            gestureRecognizers: const <Factory<
                OneSequenceGestureRecognizer>>{},
            hitTestBehavior: PlatformViewHitTestBehavior.opaque,
          );
        },
        onCreatePlatformView: (params) {
          return PlatformViewsService.initSurfaceAndroidView(
            id: params.id,
            viewType: viewType,
            layoutDirection: TextDirection.ltr,
            creationParams: <String, dynamic>{
              "native_view_type": nativeViewType.idx
            },
            creationParamsCodec: const StandardMessageCodec(),
            onFocus: () {
              params.onFocusChanged(true);
            },
          )
            ..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)
            ..addOnPlatformViewCreatedListener((int viewId) {
              this.viewId = viewId;
              onPlatformViewCreated(viewId);
            })
            ..create();
        },
      );
    } else {
      TTFLogger.i('TTVideoPlayerView', 'use TextureLayer');
      nativeView = AndroidView(
        viewType: viewType,
        onPlatformViewCreated: (int viewId) {
          this.viewId = viewId;
          onPlatformViewCreated(viewId);
        },
        creationParams: <String, dynamic>{
          "native_view_type": nativeViewType.idx
        },
        creationParamsCodec: const StandardMessageCodec(),
      );
    }
  } else if (Platform.isIOS) {
    nativeView = UiKitView(
      viewType: viewType,
      onPlatformViewCreated: (int viewId) {
        this.viewId = viewId;
        onPlatformViewCreated(viewId);
      },
      creationParams: const {},
      creationParamsCodec: const StandardMessageCodec(),
    );
  } else {
    throw UnsupportedError("Unsupported Platform");
  }
}