API Reference
Flutter App IntentsClient
The main client class for managing App Intents:
Methods
registerIntent(AppIntent intent, handler)
- Register a single intent with handlerregisterIntents(Map<AppIntent, handler>)
- Register multiple intentsunregisterIntent(String identifier)
- Remove an intentgetRegisteredIntents()
- Get all registered intentsupdateShortcuts()
- Refresh app shortcutsdonateIntent(String identifier, parameters)
- Basic intent donation for predictiondonateIntentWithMetadata(identifier, parameters, {relevanceScore, context, timestamp})
- Enhanced donation with metadatadonateIntentBatch(List<IntentDonation> donations)
- Batch donate multiple intents efficiently
AppIntent
Represents an App Intent configuration:
const AppIntent({
required String identifier, // Unique ID
required String title, // Display name
required String description, // What it does
List<AppIntentParameter> parameters = const [],
bool isEligibleForSearch = true,
bool isEligibleForPrediction = true,
AuthenticationPolicy authenticationPolicy = AuthenticationPolicy.none,
});
Properties
identifier
(String): Unique identifier for the intenttitle
(String): Human-readable title shown in Siri/Shortcutsdescription
(String): Description of what the intent doesparameters
(List<AppIntentParameter>): List of parameters this intent acceptsisEligibleForSearch
(bool): Whether intent appears in Spotlight searchisEligibleForPrediction
(bool): Whether Siri can suggest this intentauthenticationPolicy
(AuthenticationPolicy): Authentication requirements
AppIntentParameter
Defines parameters that can be passed to intents:
const AppIntentParameter({
required String name, // Parameter name
required String title, // Display title
required AppIntentParameterType type,
String? description,
bool isOptional = false,
dynamic defaultValue,
});
Properties
name
(String): Internal parameter name used in codetitle
(String): Human-readable title shown to userstype
(AppIntentParameterType): Data type of the parameterdescription
(String?): Optional description of the parameterisOptional
(bool): Whether the parameter is requireddefaultValue
(dynamic): Default value if not provided
AppIntentParameterType
Supported parameter types:
AppIntentParameterType.string
- Text inputAppIntentParameterType.integer
- Whole numbersAppIntentParameterType.boolean
- True/false valuesAppIntentParameterType.double
- Decimal numbersAppIntentParameterType.date
- Date/time valuesAppIntentParameterType.url
- Web URLsAppIntentParameterType.file
- File referencesAppIntentParameterType.entity
- Custom app-specific types
AppIntentResult
Result returned from intent execution:
Successful Result
AppIntentResult.successful(
value: 'Operation completed',
needsToContinueInApp: false,
);
Failed Result
AppIntentResult.failed(
error: 'Something went wrong',
);
Properties
isSuccess
(bool): Whether the intent executed successfullyvalue
(String?): Result message or value returnederror
(String?): Error message if execution failedneedsToContinueInApp
(bool): Whether the app should be opened/focused
AppIntentBuilder
Fluent API for creating intents:
final intent = AppIntentBuilder()
.identifier('my_intent')
.title('My Intent')
.description('Does something useful')
.parameter(myParameter)
.eligibleForSearch(true)
.authenticationPolicy(AuthenticationPolicy.requiresAuthentication)
.build();
Methods
identifier(String id)
- Set the unique identifiertitle(String title)
- Set the display titledescription(String desc)
- Set the descriptionparameter(AppIntentParameter param)
- Add a parametereligibleForSearch(bool eligible)
- Set search eligibilityeligibleForPrediction(bool eligible)
- Set prediction eligibilityauthenticationPolicy(AuthenticationPolicy policy)
- Set auth requirementsbuild()
- Build the final AppIntent object
Authentication Policies
Control when intents can be executed:
AuthenticationPolicy.none
- No authentication requiredAuthenticationPolicy.requiresAuthentication
- User must be authenticatedAuthenticationPolicy.requiresUnlockedDevice
- Device must be unlocked
Intent Donation Classes
IntentDonation
Represents a single intent donation with metadata:
const IntentDonation({
required String identifier,
required Map<String, dynamic> parameters,
required double relevanceScore,
Map<String, dynamic>? context,
DateTime? timestamp,
});
Factory Constructors
IntentDonation.highRelevance()
- Creates donation with relevance 1.0IntentDonation.userInitiated()
- Creates donation with relevance 0.9IntentDonation.mediumRelevance()
- Creates donation with relevance 0.7IntentDonation.automated()
- Creates donation with relevance 0.5IntentDonation.lowRelevance()
- Creates donation with relevance 0.3
Error Handling
Common Exceptions
AppIntentException
- Base exception class for intent-related errorsIntentRegistrationException
- Errors during intent registrationIntentExecutionException
- Errors during intent executionInvalidParameterException
- Invalid parameter values or types
Best Practices
try {
final result = await handleIntent(parameters);
return AppIntentResult.successful(value: result);
} catch (e) {
// Log the error for debugging
print('Intent execution failed: $e');
// Return user-friendly error message
return AppIntentResult.failed(
error: 'Unable to complete the requested action',
);
}
FlutterAppIntentsService
Static service class providing utility methods:
Methods
// Enhanced intent donation
static Future<void> donateIntentWithMetadata(
String identifier,
Map<String, dynamic> parameters, {
required double relevanceScore,
Map<String, dynamic>? context,
DateTime? timestamp,
});
// Batch intent donation
static Future<void> donateIntentBatch(
List<IntentDonation> donations,
);
// Basic intent donation
static Future<void> donateIntent(
String identifier,
Map<String, dynamic> parameters,
);
Example Usage
Complete Intent Setup
class MyAppIntents {
static Future<void> setupIntents() async {
final client = FlutterAppIntentsClient.instance;
// Create intent with builder
final incrementIntent = AppIntentBuilder()
.identifier('increment_counter')
.title('Increment Counter')
.description('Increments the counter by one')
.parameter(const AppIntentParameter(
name: 'amount',
title: 'Amount',
type: AppIntentParameterType.integer,
isOptional: true,
defaultValue: 1,
))
.eligibleForSearch(true)
.eligibleForPrediction(true)
.build();
// Register with handler
await client.registerIntent(incrementIntent, _handleIncrement);
}
static Future<AppIntentResult> _handleIncrement(
Map<String, dynamic> parameters,
) async {
try {
final amount = parameters['amount'] as int? ?? 1;
// Your business logic
final newValue = await incrementCounter(amount);
// Enhanced donation
await FlutterAppIntentsService.donateIntentWithMetadata(
'increment_counter',
parameters,
relevanceScore: 0.9,
context: {'feature': 'counter', 'userAction': true},
);
return AppIntentResult.successful(
value: 'Counter is now $newValue',
);
} catch (e) {
return AppIntentResult.failed(
error: 'Failed to increment counter: $e',
);
}
}
}