generating-flutter-ui
Skill7 starsChanged 8 months agoMITView on GitHub
Generative UI (GenUI) for Flutter with the genui 0.10 package (SurfaceController, A2uiTransportAdapter, Conversation, Surface) and an LLM backend such as Firebase AI Logic (firebase_ai). Use when the layout must come from model output, for chat-based UI generation, prompt-to-UI systems, or AI-driven dashboards. Do not use for static screens.
In this repository41 other files it gives its agents.
- .github/copilot-instructions.mdCopilot instructions
- skill-creatorSkill
- flutter-dbSkill
- flutter-routingSkill
- flutter-state-managementSkill
- bloc-signalsSkill
- configuring-codemagicSkill
- applying-effective-dartSkill
- deploying-with-fastlaneSkill
- integrating-firebaseSkill
- implementing-fl-chartSkill
- integrating-google-adsSkill
- animating-flutter-widgetsSkill
- routing-with-autorouteSkill
- implementing-flutter-blocSkill
- configuring-deep-linksSkill
- persisting-data-with-driftSkill
- building-flutter-production-appsSkill
- routing-with-gorouterSkill
- managing-hive-storageSkill
- using-flutter-hooksSkill
- running-flutter-isolatesSkill
- managing-flutter-provider-stateSkill
- implementing-responsive-layoutsSkill
- implementing-riverpodSkill
- managing-secure-storageSkill
- flutter-setupSkill
- managing-shared-preferencesSkill
- implementing-flutter-social-authSkill
- flutter-testingSkill
- generating-freezed-modelsSkill
- configuring-github-actionsSkill
- building-jaspr-web-appsSkill
- testing-with-marionetteSkill
- implementing-openapi-in-dartSkill
- integrating-revenuecatSkill
- integrating-sentrySkill
- developing-serverpod-backendSkill
- building-shadcn-flutter-uiSkill
- integrating-supabaseSkill
- converting-ts-to-dartSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 131
Before you write user-input UI, ask which widgets the app should use.
- Very specific: line 137
Do not add genui_firebase_ai.
- Very specific: line 138
Do not use the 0.7-era names ContentGenerator, GenUiConversation, A2uiMessageProcessor, or the manual DataModel wiring.
- Distinctive: line 140
Use GenUI only for AI-driven structure.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Flutter Generative UI (GenUI)
Goal
Render UI that an AI model generates at runtime, using genui 0.10. Use it only for features whose structure depends on model output. Static screens should use normal widgets.
Instructions
1. Setup
flutter pub add genui firebase_ai firebase_core- macOS and iOS: allow outbound network access in
{ios,macos}/Runner/*.entitlementswithcom.apple.security.network.clientset totrue. - Initialize Firebase and configure GenUI logging before
runApp.DefaultFirebaseOptionscomes from the FlutterFire CLI.
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
configureLogging(logCallback: (level, msg) => debugPrint('GenUI $level: $msg'));
runApp(const MaterialApp(home: GenUiPage()));
}2. Core objects
| Object | Role |
SurfaceController(catalogs: [...]) | Holds the widget catalog and the state of each surface. |
A2uiTransportAdapter(onSend: ...) | Sends user messages to the model. Feed model output back with addChunk(text). |
Conversation(controller:, transport:) | Runs the loop. Exposes events and sendRequest(ChatMessage). |
Surface(surfaceContext: controller.contextFor(id)) | Renders one surface. |
3. Example: Firebase AI Logic backend
This file compiles with flutter analyze against the pinned versions.
import 'package:firebase_ai/firebase_ai.dart';
import 'package:flutter/material.dart';
import 'package:genui/genui.dart' hide TextPart;
import 'package:genui/genui.dart' as genui;
class GenUiPage extends StatefulWidget {
const GenUiPage({super.key});
@override
State<GenUiPage> createState() => _GenUiPageState();
}
class _GenUiPageState extends State<GenUiPage> {
late final SurfaceController _controller;
late final A2uiTransportAdapter _transport;
late final Conversation _conversation;
late final ChatSession _chatSession;
final List<String> _surfaceIds = [];
@override
void initState() {
super.initState();
final catalog = BasicCatalogItems.asCatalog();
_controller = SurfaceController(catalogs: [catalog]);
_transport = A2uiTransportAdapter(onSend: _sendAndReceive);
_conversation = Conversation(controller: _controller, transport: _transport);
final model = FirebaseAI.googleAI().generativeModel(model: 'gemini-3-flash-preview');
_chatSession = model.startChat();
_conversation.events.listen((event) {
switch (event) {
case ConversationSurfaceAdded added:
setState(() => _surfaceIds.add(added.surfaceId));
case ConversationSurfaceRemoved removed:
setState(() => _surfaceIds.remove(removed.surfaceId));
case ConversationContentReceived content:
debugPrint(content.text);
case ConversationError error:
debugPrint('${error.error}');
default:
}
});
final promptBuilder = PromptBuilder.chat(
catalog: catalog,
systemPromptFragments: ['You are a helpful assistant.'],
);
_conversation.sendRequest(ChatMessage.system(promptBuilder.systemPromptJoined()));
}
Future<void> _sendAndReceive(ChatMessage msg) async {
final buffer = StringBuffer();
for (final part in msg.parts) {
if (part.isUiInteractionPart) {
buffer.write(part.asUiInteractionPart!.interaction);
} else if (part is genui.TextPart) {
buffer.write(part.text);
}
}
if (buffer.isEmpty) return;
final response = await _chatSession.sendMessage(Content.text(buffer.toString()));
if (response.text?.isNotEmpty ?? false) {
_transport.addChunk(response.text!);
}
}
@override
Widget build(BuildContext context) {
return Column(children: [
for (final id in _surfaceIds) Surface(surfaceContext: _controller.contextFor(id)),
]);
}
@override
void dispose() {
_conversation.dispose();
super.dispose();
}
}4. Events
Handle ConversationSurfaceAdded and ConversationSurfaceRemoved by updating the list of surface IDs, then build one Surface per ID. Handle ConversationContentReceived for plain text and ConversationError for failures.
5. System prompt
Build the prompt with PromptBuilder.chat(catalog:, systemPromptFragments:), then send ChatMessage.system(promptBuilder.systemPromptJoined()) once. systemPrompt() is a method that returns an Iterable<String>, not a String.
6. Ask about input widgets
Before you write user-input UI, ask which widgets the app should use. The official guide treats this as a question for the user, not a default.
7. Official reference
The genui package ships an official integration guide at skills/integrate-genui-firebase/SKILL.md inside the installed package. Read it when you need the full Firebase setup steps.
Constraints
- Do not add
genui_firebase_ai. It is discontinued. Callfirebase_aidirectly fromonSend. - Do not use the 0.7-era names
ContentGenerator,GenUiConversation,A2uiMessageProcessor, or the manualDataModelwiring. They do not match genui 0.10.4. - Dispose the
Conversationindispose(). - Use GenUI only for AI-driven structure. Do not use it for static screens or ordinary layouts.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

