flutter_copilot
Turn your Flutter app into an AI-operable interface — no screenshots, no overlay chatbot, just natural-language goals becoming real UI actions, natively.
Demo
https://github.com/user-attachments/assets/7dcb8504-00b3-4f68-80d3-19f74df75417
If you find flutter_copilot interesting or useful, please star the repo. It helps others discover the project and encourages continued development. Every star counts.
flutter_copilot gives your Flutter app an invisible AI copilot that can understand the current screen, decide what to do next, and operate the UI on behalf of the user.
Instead of building yet another chatbot inside your app, you get real agentic behavior: the copilot inspects the visible Flutter UI, chooses actions, taps buttons, types into fields, scrolls lists, waits for changes, and continues until the goal is complete.
final controller = CopilotController.of(context);
final result = await controller.run(
'Go to settings, turn on dark mode, enable weekly summary emails, and save.',
);
That single line can navigate multiple screens, toggle controls, fill forms, and confirm changes — all driven by the model through Flutter's own semantics tree.
Table of Contents
Why flutter_copilot
Native to Flutter
flutter_copilot is designed specifically for Flutter apps. It works with Flutter's own UI and semantics system instead of depending on brittle screenshots, OCR, or external automation layers. The copilot understands the app through structured UI information, not by guessing pixels.
No screenshots required
Many AI UI agents depend on screenshots and vision models. That can be slower, more expensive, less private, and less deterministic.
flutter_copilot works from the Flutter semantics tree, so the model sees a compact, structured representation of the current UI:
- Lower token usage than sending screenshots.
- Better privacy because screenshots never leave the device.
- More deterministic UI understanding.
- Better compatibility with accessibility-friendly apps.
- Less dependence on visual layout changes.
No overlay chat UI required
The copilot runs invisibly inside your app. You do not need to redesign your product around a chatbot bubble. Trigger it from your own UI, voice input, support flow, onboarding flow, command palette, or any custom entry point.
Natural-language app control
Users express goals naturally:
- "Create a new task called Buy milk."
- "Find my last invoice."
- "Change my profile name."
- "Turn on dark mode."
- "Search for flights to Paris."
- "Delete the completed items."
- "Help me finish this form."
The copilot translates the goal into UI actions.
Works with the UI you already have
You do not need to rebuild your app around special AI screens. Wrap your app, provide a model adapter, and expose the current UI through Flutter semantics. The better your accessibility labels are, the better the copilot becomes.
Accessibility improvements become AI improvements
Because flutter_copilot relies on semantics, improving accessibility also improves the AI agent's ability to understand the app. One improvement helps both screen reader users and AI-assisted navigation:
- Screen reader users.
- Voice control users.
- AI-assisted app navigation.
- Automated testing and QA.
Safer than free-form code execution
The model does not need direct access to arbitrary app internals. It receives a controlled set of tools and can only perform actions the developer exposes. This makes it easier to build safety policies around sensitive flows such as payments, deletion, or account changes.
Tool-based and inspectable
The copilot calls explicit tools — tap, type_text, scroll, wait, done, fail — not free-form code. That makes behavior easier to log, debug, replay, and evaluate. A developer can inspect what the model saw, what action it chose, why it stopped, and whether the action succeeded.
How It Works
flutter_copilot runs an observe → plan → act loop:
┌─────────────────────────────────────────────────────────┐
│ User Goal │
│ "Go to settings, turn on dark mode, and save." │
└──────────────────────┬──────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ 1. OBSERVE ─ Capture the Flutter semantics tree │
│ Compress to model-friendly JSON │
└──────────────────────┬──────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ 2. PLAN ─ Send scene JSON + goal to the LLM │
│ Model selects tool calls (actions) │
└──────────────────────┬──────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ 3. ACT ─ Execute actions via semantics or │
│ pointer events │
│ Safety policy check before execution │
└──────────────────────┬──────────────────────────────────┘
│
▼
┌────────┴────────┐
│ Goal complete? │
└────────┬────────┘
yes │ no
◄────┘────►
┌────────┐ ┌──────────┐
│ DONE │ │ Re-observe│
└────────┘ └──────────┘
Each cycle:
- Observe —
SceneCapture reads Flutter's live semantics tree and SceneCompressor reduces it to the most relevant nodes.
- Plan — The compressed scene JSON and user goal are sent to the LLM. The model returns tool calls (actions).
- Act —
ActionExecutor performs the action using semantics actions when available, falling back to pointer events.
- Verify — A fresh scene is captured. The loop continues until the model calls
done or fail.
Key Features
| Feature |
Description |
| Semantics-first |
Reads Flutter's semantics tree — no screenshots, no OCR, no vision models |
| 18 action types |
Tap, long press, type, clear, replace, scroll, drag, slider, dismiss, keyboard, and more |
| Action batching |
Multiple independent actions in a single model step |
| Parallel execution |
Independent batched actions run concurrently via Future.wait |
| Safety policy |
Built-in guardrails block destructive actions (payments, deletion, logout) |
| Confirmation flow |
Sensitive actions pause and ask the app/user before proceeding |
| Retry & recovery |
Exponential backoff for transient LLM failures |
| Conversation memory |
Multi-turn context across runs within a session |
| Custom tools |
Extend the action set with developer-defined handlers |
| Analytics & metrics |
Track success rates, duration, step counts, and token usage |
| Screenshot fallback |
Optional vision context for widgets with poor semantics |
| Event streaming |
Real-time progress events for UI feedback and logging |
| Provider-agnostic |
Works with OpenAI and any OpenAI-compatible API |
| Sealed result types |
CopilotCompleted, CopilotFailed, CopilotCancelled, CopilotMaxStepsExceeded |
| Configurable autonomy |
fullAccess or askBeforeSensitiveActions mode |
| Fake adapter for tests |
Deterministic FakeLlmAdapter for unit and widget tests |
| Zero overlays |
No chatbot bubble, no injected UI — runs invisibly inside your app |
| Cross-platform |
Android, iOS, Linux, macOS, Windows, and Web |
Quick Start
1. Add the dependency
dependencies:
flutter_copilot: ^0.12.0
2. Wrap your app with CopilotApp
import 'package:flutter/material.dart';
import 'package:flutter_copilot/flutter_copilot.dart';
void main() {
runApp(
CopilotApp(
config: CopilotConfig(
llm: OpenAILlmAdapter(
apiKey: 'YOUR_API_KEY',
model: 'gpt-4.1',
),
debugLogging: true,
),
child: const MyApp(),
),
);
}
3. Run a goal from anywhere in your app
final controller = CopilotController.of(context);
final result = await controller.run(
'Open profile, update display name to Alex, and save.',
);
switch (result) {
case CopilotCompleted(:final summary):
print('Done: $summary');
case CopilotFailed(:final reason):
print('Failed: $reason');
case CopilotCancelled():
print('Cancelled by user');
case CopilotMaxStepsExceeded(:final steps):
print('Stopped after $steps steps');
}
That's it. The copilot handles navigation, form filling, toggling controls, and confirmation — all from a single natural-language string.
Configuration
CopilotConfig(
// Required: the LLM adapter to use
llm: OpenAILlmAdapter(apiKey: '...', model: 'gpt-4.1'),
// Maximum observe→plan→act cycles before stopping (default: 12)
maxSteps: 12,
// Delay after actions so Flutter can rebuild and settle (default: 300ms)
settleDelay: Duration(milliseconds: 300),
// Developer-owned rules for denied and approval-gated UI targets
safetyPolicy: CopilotSafetyPolicy.defaults,
// Autonomy level: fullAccess or askBeforeSensitiveActions (default)
accessMode: CopilotAccessMode.askBeforeSensitiveActions,
// Callback when the copilot needs approval to continue
onConfirmationRequest: (request) async {
return await showConfirmDialog(request.goal, request.reason);
},
// Optional event callback for logging or UI progress
onEvent: (event) => print(event),
// Print copilot events with debugPrint (default: false)
debugLogging: true,
// --- v0.12.0 new options ---
// Retry configuration for transient LLM failures
retryConfig: RetryConfig(
maxRetries: 3,
baseDelay: Duration(milliseconds: 500),
maxDelay: Duration(seconds: 10),
),
// Enable multi-turn conversation memory
memoryStore: InMemoryStore(),
memoryContextLimit: 5,
// Register custom action handlers
customActions: {
'my_custom_tool': MyCustomHandler(),
},
// Collect usage metrics
metricsCollector: MetricsCollector(),
// Optional screenshot fallback (default: false)
enableScreenshots: false,
screenshotAsFallback: true,
)
Supported Actions
The copilot can perform 18 distinct action types against the Flutter UI:
| Action |
Tool Name |
Description |
| Tap |
tap |
Tap a visible UI node by id |
| Long Press |
long_press |
Long-press a visible node (context menus, drag handles) |
| Type Text |
type_text |
Enter text into a text field |
| Clear Text |
clear_text |
Clear all text from a text field |
| Replace Text |
replace_text |
Replace all text in a text field |
| Set Text Selection |
set_text_selection |
Set cursor/selection range in a text field |
| Keyboard Action |
keyboard_action |
Send keyboard events (enter, tab, escape, backspace, etc.) |
| Scroll |
scroll |
Scroll a scrollable area in any direction |
| Drag |
drag |
Drag across a node (swipe buttons, carousels, maps) |
| Long Press Drag |
long_press_drag |
Hold then drag (reorder handles, drag handles) |
| Slider to Value |
slider_to_value |
Drag a slider to a normalized 0.0–1.0 value |
| Adjust Value |
adjust_value |
Semantic increase/decrease on steppers and sliders |
| Dismiss |
dismiss |
Dismiss a dismissible node (semantic or drag fallback) |
| System Back |
system_back |
Navigate back when no text field is focused |
| Wait |
wait |
Wait for loading, animation, or async UI state |
| Request Confirmation |
request_confirmation |
Ask the app/user before a sensitive step |
| Done |
done |
Mark the goal as complete |
| Fail |
fail |
Stop when the goal cannot be completed |