Google is committed to advancing racial equity for Black communities. See how.

connect method

*[<Null safety>](https://dart.dev/null-safety)*

Future<void> connect ({bool hitTestable = true, bool focusable = true, dynamic viewOcclusionHint = Rect.zero})

Connects to the platform view given it's viewId.

Called by FuchsiaView when the platform view is ready to be initialized and should not be called directly. This MUST NOT be called directly.

Implementation

Future<void> connect({
  bool hitTestable = true,
  bool focusable = true,
  Rect viewOcclusionHint = Rect.zero,
}) async {
  if (_viewCreated) return;
  _viewCreated = true; // Only allow this to be called once

  // Setup callbacks for receiving view events.
  FuchsiaViewsService.instance.register(viewId, (call) async {
    switch (call.method) {
      case 'View.viewConnected':
        _whenConnected.complete();
        onViewConnected?.call(this);
        break;
      case 'View.viewDisconnected':
        _whenConnected = Completer();
        onViewDisconnected?.call(this);
        break;
      case 'View.viewStateChanged':
        final state =
            call.arguments['state'] == 1 || call.arguments['state'] == true;
        onViewStateChanged?.call(this, state);
        break;
      default:
        print('Unknown method call from platform view channel: $call');
    }
  });

  // Now send a create message to the platform view.
  return FuchsiaViewsService.instance.createView(
    viewId,
    hitTestable: hitTestable,
    focusable: focusable,
    viewOcclusionHint: viewOcclusionHint,
  );
}