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

ChildViewConnection constructor

*<Null safety>*

ChildViewConnection(dynamic viewHolderToken, {dynamic viewRef, ChildViewConnectionCallback? onAvailable, ChildViewConnectionCallback? onUnavailable, ChildViewConnectionStateCallback? onStateChanged, bool usePlatformView: false})

Creates this connection from a ViewHolderToken.

Implementation

ChildViewConnection(
  this.viewHolderToken, {
  this.viewRef,
  this.onAvailable,
  this.onUnavailable,
  this.onStateChanged,
  this.usePlatformView = false,
})  : assert(viewHolderToken.value != null && viewHolderToken.value.isValid),
      assert(
          viewRef?.reference == null || viewRef!.reference.handle!.isValid) {
  if (!usePlatformView) {
    _sceneHost = SceneHost(
        viewHolderToken.value.passHandle(),
        (onAvailable == null)
            ? null
            : () {
                onAvailable!(this);
              },
        (onUnavailable == null)
            ? null
            : () {
                onUnavailable!(this);
              },
        (onStateChanged == null)
            ? null
            : (bool state) {
                onStateChanged!(this, state);
              });
  } else {
    try {
      _platformViewChannel.setMethodCallHandler((call) async {
        switch (call.method) {
          case 'View.viewConnected':
            onAvailable?.call(this);
            break;
          case 'View.viewDisconnected':
            onUnavailable?.call(this);
            break;
          case 'View.viewStateChanged':
            onStateChanged?.call(this, call.arguments['state'] ?? false);
            break;
          default:
            print('Unknown method call from platform view channel: $call');
        }
      });
    } on Exception catch (e) {
      print('Failed to set method call handler: $e');
    }
  }
}