app_intents_codegen
Code generator for Flutter App Intents. Produces Swift, Kotlin, and Dart code from @IntentSpec and @EntitySpec annotations.
Features
iOS (Swift)
- Generate iOS 17+ Swift code for App Intents
ProvidesDialogfor Siri/Shortcuts dialog feedbackParameterSummaryfor Shortcuts UI displayAppEnumgeneration for enum parameters- Entity
DisplayRepresentationwith SF Symbol image support - Support for
@AppShortcutand@AppShortcutsProvider
Android (Kotlin)
- Generate Android 16+ (API 36) Kotlin code for AppFunctions
@AppFunctionannotated methods for AI agent integration@AppFunctionSerializabledata classes for entitiesAppFunctionsBridgesingleton for MethodChannel communication
Common
- Generate Dart initialization code for intent handlers
- CLI tools for Swift and Kotlin code generation
- Integration with
build_runnerfor Dart code generation
Installation
dependencies:
app_intents: ^0.6.1
app_intents_annotations: ^0.6.1
dev_dependencies:
app_intents_codegen: ^0.6.1
build_runner: ^2.4.0
Usage
1. Define Intents and Entities
Create your intent and entity specifications using annotations from app_intents_annotations:
// lib/intents/create_task_intent.dart
import 'package:app_intents/app_intents.dart';
import 'package:app_intents_annotations/app_intents_annotations.dart';
part 'create_task_intent.intent.dart';
@IntentSpec(
identifier: 'com.example.CreateTaskIntent',
title: 'Create Task',
)
class CreateTaskIntentSpec extends IntentSpecBase {
@IntentParam(title: 'Title')
final String title;
CreateTaskIntentSpec({required this.title});
}
Future<Task> createTaskIntentHandler({required String title}) async {
// Your implementation
}
2. Generate Dart Code
Run build_runner to generate Dart initialization code:
dart run build_runner build --delete-conflicting-outputs
This creates *.intent.dart part files with initializeXxxAppIntents() functions.
3. Generate Native Code
Use the CLI tools to generate native code:
# iOS: Generate Swift code
dart run app_intents_codegen:generate_swift -i lib -o ios/Runner/GeneratedIntents
# Android: Generate Kotlin code
dart run app_intents_codegen:generate_kotlin -i lib -o android/app/src/main/kotlin/com/example/app/generated -p com.example.app.generated
Swift CLI Options
| Option | Description | Default |
|---|---|---|
-i, --input |
Input directory to scan | lib |
-o, --output |
Output directory for Swift files | ios/Runner/GeneratedIntents |
-f, --file |
Output filename | GeneratedAppIntents.swift |
Kotlin CLI Options
| Option | Description | Default |
|---|---|---|
-i, --input |
Input directory to scan | lib |
-o, --output |
Output directory for Kotlin files | (required) |
-p, --package |
Kotlin package name | (required) |
-f, --file |
Output filename | GeneratedAppFunctions.kt |
4. Integrate Generated Code
Initialize the generated handlers in your Flutter app:
void main() {
initializeCreateTaskAppIntents();
initializeTaskEntityAppIntents();
// ... other initializations
runApp(MyApp());
}
Generated Code
Swift Output
The generator produces iOS 17+ compatible Swift code:
import AppIntents
import UIKit
@available(iOS 17.0, *)
struct CreateTaskIntentSpec: AppIntent {
static var title: LocalizedStringResource = "Create Task"
static var description: IntentDescription =
IntentDescription("Create a new task")
@available(iOS 26.0, *)
static var supportedModes: IntentModes { .foreground }
static var openAppWhenRun: Bool { true }
@Parameter(title: "Title")
var title: String
@MainActor
func perform() async throws -> some IntentResult & ProvidesDialog {
// URL scheme handling for Flutter integration
// ...
return .result(dialog: .init("Created task \"\(title)\""))
}
}
Dart Output
Generated part files contain type-safe Params classes and handler registration:
part of 'create_task_intent.dart';
class CreateTaskIntentParams {
final String title;
const CreateTaskIntentParams({required this.title});
factory CreateTaskIntentParams.fromMap(Map<String, dynamic> map) {
return CreateTaskIntentParams(title: map['title'] as String);
}
}
void initializeCreateTaskAppIntents() {
AppIntents().registerIntentHandler(
'com.example.CreateTaskIntent',
(params) async {
final p = CreateTaskIntentParams.fromMap(params);
await createTaskIntentHandler(title: p.title);
return <String, dynamic>{};
},
);
}
Related Packages
- app_intents - Flutter plugin for iOS App Intents and Android AppFunctions
- app_intents_annotations - Annotations for defining intents and entities
License
MIT License - see the LICENSE file for details.
Libraries
- app_intents_codegen
- Code generator for Flutter AppIntents.
- builder
- Builder entry point for build_runner integration.