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

connect method

*<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.

Implementation

Future<void> connect({
  bool hitTestable = true,
  bool focusable = true,
  Rect viewOcclusionHint = Rect.zero,
}) async {
  if (_whenConnected.isCompleted) return;

  // Setup callbacks for receiving view events.
  fuchsiaViewsService.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.createView(
    viewId,
    hitTestable: hitTestable,
    focusable: focusable,
    viewOcclusionHint: viewOcclusionHint,
  );
}