bind method

Future<void> bind(
  1. MiniProgramInteractionController controller
)

Implementation

Future<void> bind(MiniProgramInteractionController controller) async {
  if (_bound) throw StateError('Interaction channel is already bound.');
  _bound = true;
  _channel.setMethodCallHandler((call) async {
    if (call.method != 'dispatch' || call.arguments is! Map) {
      throw const FormatException('Invalid interaction relay request.');
    }
    return controller.handleRequest(
      Map<String, dynamic>.from(call.arguments as Map),
    );
  });
  try {
    await _channel.invokeMethod<void>('register');
  } on MissingPluginException {
    // The direct Dart controller remains usable in embedded/non-Android hosts.
  }
}