initUiKitView method

Future<UiKitViewController> initUiKitView ({@required int id, @required String viewType, @required TextDirection layoutDirection, dynamic creationParams, MessageCodec creationParamsCodec })

This is work in progress, not yet ready to be used, and requires a custom engine build. Creates a controller for a new iOS UIView.

id is an unused unique identifier generated with platformViewsRegistry.

viewType is the identifier of the iOS view type to be created, a factory for this view type must have been registered on the platform side. Platform view factories are typically registered by plugin code.

The id,viewType, and layoutDirection parameters must not be null. If creationParams is non null then cretaionParamsCodec must not be null.

Implementation

static Future<UiKitViewController> initUiKitView({
  @required int id,
  @required String viewType,
  @required TextDirection layoutDirection,
  dynamic creationParams,
  MessageCodec<dynamic> creationParamsCodec,
}) async {
  assert(id != null);
  assert(viewType != null);
  assert(layoutDirection != null);
  assert(creationParams == null || creationParamsCodec != null);

  // TODO(amirh): pass layoutDirection once the system channel supports it.
  final Map<String, dynamic> args = <String, dynamic> {
    'id': id,
    'viewType': viewType,
  };
  if (creationParams != null) {
    final ByteData paramsByteData = creationParamsCodec.encodeMessage(creationParams);
    args['params'] = Uint8List.view(
      paramsByteData.buffer,
      0,
      paramsByteData.lengthInBytes,
    );
  }
  await SystemChannels.platform_views.invokeMethod('create', args);
  return UiKitViewController._(id, layoutDirection);
}