child method

Widget child(
  1. double width,
  2. double height
)

Implementation

Widget child(double width, double height) {
  /// using [Hybrid Composition]
  /// ref: `https://flutter.dev/docs/development/platform-integration/platform-views`
  // This is used in the platform side to register the view.
  const String viewType = 'webview-view-type';
  // Pass parameters to the platform side.
  final Map<String, dynamic> creationParams = <String, dynamic>{};
  creationParams['width'] = width;
  creationParams['height'] = height;
  creationParams['content'] = content;
  // WebcontentConverter.logger("creationParams $creationParams");
  switch (defaultTargetPlatform) {
    case TargetPlatform.android:
      return PlatformViewLink(
        viewType: viewType,
        surfaceFactory: (
          BuildContext context,
          PlatformViewController controller,
        ) {
          return AndroidViewSurface(
            controller: controller as AndroidViewController,
            gestureRecognizers: const <
                Factory<OneSequenceGestureRecognizer>>{},
            hitTestBehavior: PlatformViewHitTestBehavior.opaque,
          );
        },
        onCreatePlatformView: (PlatformViewCreationParams params) {
          return PlatformViewsService.initSurfaceAndroidView(
            id: params.id,
            viewType: viewType,
            layoutDirection: TextDirection.ltr,
            creationParams: creationParams,
            creationParamsCodec: const StandardMessageCodec(),
          )
            ..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)
            ..create();
        },
      );
    case TargetPlatform.iOS:
      return UiKitView(
        viewType: viewType,
        layoutDirection: TextDirection.ltr,
        creationParams: creationParams,
        creationParamsCodec: const StandardMessageCodec(),
      );

    default:
      throw UnsupportedError("Unsupported platform view");
  }
}