app_intents_codegen 0.6.0 copy "app_intents_codegen: ^0.6.0" to clipboard
app_intents_codegen: ^0.6.0 copied to clipboard

Code generator for Flutter AppIntents. Produces Swift and Dart code from @IntentSpec and @EntitySpec annotations.

app_intents_codegen #

pub package License: MIT

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
  • ProvidesDialog for Siri/Shortcuts dialog feedback
  • ParameterSummary for Shortcuts UI display
  • AppEnum generation for enum parameters
  • Entity DisplayRepresentation with SF Symbol image support
  • Support for @AppShortcut and @AppShortcutsProvider

Android (Kotlin) #

  • Generate Android 16+ (API 36) Kotlin code for AppFunctions
  • @AppFunction annotated methods for AI agent integration
  • @AppFunctionSerializable data classes for entities
  • AppFunctionsBridge singleton for MethodChannel communication

Common #

  • Generate Dart initialization code for intent handlers
  • CLI tools for Swift and Kotlin code generation
  • Integration with build_runner for Dart code generation

Installation #

dependencies:
  app_intents: ^0.6.0
  app_intents_annotations: ^0.6.0

dev_dependencies:
  app_intents_codegen: ^0.6.0
  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

@available(iOS 17.0, *)
struct CreateTaskIntent: AppIntent {
    static var title: LocalizedStringResource = "Create Task"

    @Parameter(title: "Title")
    var title: String

    static var openAppWhenRun: Bool = true

    @MainActor
    func perform() async throws -> some IntentResult {
        // URL scheme handling for Flutter integration
    }
}

Dart Output #

Generated part files contain handler registration:

part of 'create_task_intent.dart';

void initializeCreateTaskAppIntents() {
  AppIntents().registerIntentHandler(
    'com.example.CreateTaskIntent',
    (params) async {
      // Handler invocation
    },
  );
}

License #

MIT License - see the LICENSE file for details.

0
likes
130
points
27
downloads

Publisher

unverified uploader

Weekly Downloads

Code generator for Flutter AppIntents. Produces Swift and Dart code from @IntentSpec and @EntitySpec annotations.

Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

MIT (license)

Dependencies

analyzer, app_intents_annotations, args, build, code_builder, dart_style, glob, path, source_gen

More

Packages that depend on app_intents_codegen