initUiKitView method Null safety

Future<UiKitViewController> initUiKitView(
  1. {required int id,
  2. required String viewType,
  3. required TextDirection layoutDirection,
  4. dynamic creationParams,
  5. MessageCodec? creationParamsCodec,
  6. VoidCallback? onFocus}
)

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.

onFocus is a callback that will be invoked when the UIKit view asks to get the input focus. The id,viewType, and layoutDirection parameters must not be null. If creationParams is non null then creationParamsCodec must not be null.

Implementation

static Future<UiKitViewController> initUiKitView({
  required int id,
  required String viewType,
  required TextDirection layoutDirection,
  dynamic creationParams,
  MessageCodec<dynamic>? creationParamsCodec,
  VoidCallback? onFocus,
}) 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<void>('create', args);
  if (onFocus != null) {
    _instance._focusCallbacks[id] = onFocus;
  }
  return UiKitViewController._(id, layoutDirection);
}