invokeIntent method

Future<Map<String, Object?>> invokeIntent(
  1. String id, {
  2. Map<String, Object?> args = const {},
  3. bool background = false,
})

Invokes an intent the way the system does, through the installed dispatcher.

Returns the wire map the native side would receive: {'kind': 'dialog', 'spoken': …} for a spoken answer, {'kind': 'failure', 'message': …} for an IntentResult.failure, {'kind': 'error', …} for a handler that threw.

Implementation

Future<Map<String, Object?>> invokeIntent(
  String id, {
  Map<String, Object?> args = const {},
  bool background = false,
}) {
  final handler = background ? _backgroundInvocations : _invocations;
  if (handler == null) {
    throw StateError(
      'No invocation handler installed. Call OsIntents.install() '
      '${background ? '(or installBackground) ' : ''}first.',
    );
  }
  return handler(id, args);
}