initExpensiveAndroidView static method

ExpensiveAndroidViewController initExpensiveAndroidView({
  1. required int id,
  2. required String viewType,
  3. required TextDirection layoutDirection,
  4. dynamic creationParams,
  5. MessageCodec? creationParamsCodec,
  6. VoidCallback? onFocus,
})

Creates a controller for a new Android view.

The id argument is an unused unique identifier generated with platformViewsRegistry.

The viewType argument is the identifier of the Android 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. Plugins can register a platform view factory with PlatformViewRegistry#registerViewFactory.

The creationParams argument will be passed as the args argument of PlatformViewFactory#create

The creationParamsCodec argument is the codec used to encode creationParams before sending it to the platform side. It should match the codec passed to the constructor of PlatformViewFactory. This is typically one of: StandardMessageCodec, JSONMessageCodec, StringCodec, or BinaryCodec.

The onFocus argument is a callback that will be invoked when the Android View asks to get the input focus.

The Android view will only be created after AndroidViewController.setSize is called for the first time.

If creationParams is non null then creationParamsCodec must not be null.

When this factory is used, the Android view and Flutter widgets are composed at the Android view hierarchy level.

Using this method has a performance cost on devices running Android 9 or earlier, or on underpowered devices. In most situations, you should use initAndroidView or initSurfaceAndroidView instead.

Implementation

static ExpensiveAndroidViewController initExpensiveAndroidView({
  required int id,
  required String viewType,
  required TextDirection layoutDirection,
  dynamic creationParams,
  MessageCodec<dynamic>? creationParamsCodec,
  VoidCallback? onFocus,
}) {
  final ExpensiveAndroidViewController controller = ExpensiveAndroidViewController._(
    viewId: id,
    viewType: viewType,
    layoutDirection: layoutDirection,
    creationParams: creationParams,
    creationParamsCodec: creationParamsCodec,
  );

  _instance._focusCallbacks[id] = onFocus ?? () {};
  return controller;
}