getSudGIPPlatformView2 function

Widget getSudGIPPlatformView2(
  1. dynamic onViewCreated(
    1. int viewId
    )
)

Implementation

Widget getSudGIPPlatformView2(Function(int viewId) onViewCreated) {
  String viewType = 'SudGIPPlatformView';
  if (TargetPlatform.iOS == defaultTargetPlatform) {
    return UiKitView(
      key: UniqueKey(),
      viewType: viewType,
      onPlatformViewCreated: (int viewId) {
        onViewCreated(viewId);
      },
    );
  } else if (TargetPlatform.android == defaultTargetPlatform) {
    // Pass parameters to the platform side.
    const Map<String, dynamic> creationParams = <String, dynamic>{};

    return PlatformViewLink(
      viewType: viewType,
      surfaceFactory: (context, controller) {
        return AndroidViewSurface(controller: controller as AndroidViewController, gestureRecognizers: const <Factory<OneSequenceGestureRecognizer>>{}, hitTestBehavior: PlatformViewHitTestBehavior.opaque);
      },
      onCreatePlatformView: (params) {
        return PlatformViewsService.initExpensiveAndroidView(
            id: params.id,
            viewType: viewType,
            layoutDirection: TextDirection.ltr,
            creationParams: creationParams,
            creationParamsCodec: const StandardMessageCodec(),
            onFocus: () {
              params.onFocusChanged(true);
            },
          )
          ..addOnPlatformViewCreatedListener((int viewId) {
            onViewCreated(viewId);
            params.onPlatformViewCreated(viewId);
          })
          ..create();
      },
    );

    // 使用AndroidView会导致原生的SurfaceView被置于最顶端显示
    // return AndroidView(
    //     key: UniqueKey(),
    //     viewType: viewType,
    //     onPlatformViewCreated: (int viewID) {
    //       onViewCreated(viewID);
    //     });
  }
  throw UnsupportedError('Unsupported platforms:$defaultTargetPlatform');
}