AppIntentsHarness class
Lists and runs the registered Dart handlers the way a native caller does,
under plain flutter test.
Every call is encoded with the plugin's codec and delivered on the
app_intents channel, the same entry iOS App Intents and Android
AppFunctions use. So a handler that returns a value the codec cannot carry
fails here as it would on a device, and an AppIntentError comes back with
its code unchanged. The harness never reaches a handler any other way.
late AppIntentsHarness harness;
setUp(() {
TestWidgetsFlutterBinding.ensureInitialized();
harness = AppIntentsHarness(
manifest: AppIntentsManifest.parse(
File('test/app_intents.json').readAsStringSync()),
);
initializeAppIntents(); // your generated registrations
});
tearDown(() => harness.dispose());
test('every declared intent has a handler', () {
expect(harness.list().unhandledIntents, isEmpty);
});
test('createTask', () async {
final result = await harness.run(
'com.example.taskapp.createTask', {'title': 'Milk'});
expect(result, isEmpty);
});
What the operating system decides (Siri routing, the Shortcuts UI, AppFunctions discovery) is out of reach here by design.
Constructors
-
AppIntentsHarness({AppIntentsManifest? manifest, bool validateParams = true, Duration handlerRegistrationTimeout = Duration.zero, FutureOr<
Object?> onRequestValue(String executionId, String parameter)?}) - Installs a fresh plugin instance as AppIntentsPlatform.instance.
Properties
-
cache
→ Map<
String, Object?> -
The in-memory stand-in for the App Group cache that
getCachedValue/setCachedValueread and write.final - hashCode → int
-
The hash code for this object.
no setterinherited
- manifest → AppIntentsManifest?
-
The declarations from
app_intents_codegen:describe, if given.final -
nativeCalls
→ List<
MethodCall> -
Calls the handlers made toward the native side that the harness
answered itself: donations, onscreen entity changes, App Shortcut
parameter updates. Each is the method name and its arguments.
final
-
onRequestValue
→ FutureOr<
Object?> Function(String executionId, String parameter)? -
Answers
AppIntentExecution.requestValue(#131), standing in for the system prompt. Without it a request resolves to null, which is what Android does.final -
progressReports
→ List<
HarnessProgress> -
Progress the handlers reported, in order.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- validateParams → bool
-
Whether run checks params against manifest before the call.
final
Methods
-
cancel(
String executionId, {String reason = 'userCancelled'}) → Future< void> -
Delivers a cancellation for
executionId, as the system does (#130). -
dispose(
) → void - Restores the plugin instance that was active before this harness.
-
list(
) → AppIntentsInventory - What a native caller could reach right now.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
queryEntities(
String entityIdentifier, List< String> identifiers) → Future<List< Map< >String, dynamic> > -
Runs the entity query handler for
entityIdentifierwithidentifiers. -
queryValues(
String entityIdentifier, Map< String, Object?> input) → Future<List< Map< >String, dynamic> > -
Runs the value query handler for
entityIdentifierwithinput(#51). -
run(
String identifier, [Map< String, Object?> params = const {}, bool executionScope = true]) → Future<Map< String, dynamic> > -
Runs the intent
identifierwithparamsand returns the handler's result map. -
start(
String identifier, [Map< String, Object?> params = const {}, bool executionScope = true]) → HarnessRun -
Starts the intent
identifierand returns before it finishes, so a test can HarnessRun.cancel it or watch progressReports meanwhile. -
suggestedEntities(
String entityIdentifier) → Future< List< Map< >String, dynamic> > -
Runs the suggested entities handler for
entityIdentifier. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited