Skip to content

Commit 4784663

Browse files
sfshaza2parloughantfitch
authored
GenUI for SDK docs (#12696)
This is phase 1. More to come. **Staged:** https://flutter-docs-prod--pr12696-genui-a3bvzz1o.web.app/ai/genui @gspencergoog @jacobsimionato @abdallahshaban557 @sethladd @parlough --------- Co-authored-by: Parker Lougheed <parlough@gmail.com> Co-authored-by: Amanda Fitch <18406675+antfitch@users.noreply.github.com>
1 parent 70828b5 commit 4784663

File tree

5 files changed

+720
-6
lines changed

5 files changed

+720
-6
lines changed

src/content/ai/create-with-ai.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ description: >
66
workflow.
77
---
88

9-
This guide covers how you can leverage AI tools to build AI-powered features for
10-
your Flutter apps and streamline your Flutter and Dart development.
9+
This guide covers how you can leverage AI tools to build AI-powered
10+
features for your Flutter apps and streamline your
11+
Flutter and Dart development.
1112

1213
## Overview
1314

@@ -53,6 +54,24 @@ concepts, and reduce boilerplate.
5354
[Cursor]: https://cursor.com/
5455
[Windsurf]: https://windsurf.com/
5556

57+
### GenUI SDK for Flutter {: #genui }
58+
59+
The GenUI SDK transforms text-based conversations into rich,
60+
interactive experiences. Essentially, it acts as an orchestration layer
61+
that coordinates the flow of information between your user, your
62+
Flutter widgets, and an AI agent.
63+
64+
<YouTubeEmbed id="nWr6eZKM6no" title="Getting started with GenUI"></YouTubeEmbed>
65+
66+
:::experimental
67+
The `genui` package is in
68+
alpha and is likely to change.
69+
:::
70+
71+
To learn more, see the [GenUI SDK for Flutter][] documentation.
72+
73+
[GenUI SDK for Flutter]: /ai/genui
74+
5675
### Gemini Code Assist
5776

5877
[Gemini Code Assist][] is an AI-powered collaborator available in Visual Studio
@@ -85,7 +104,7 @@ To get started, visit the [Gemini CLI][] website, or try this
85104
[Gemini CLI]: https://geminicli.com/
86105
[Gemini CLI codelab]: https://codelabs.developers.google.com/gemini-cli-hands-on
87106

88-
## Flutter Extension for Gemini CLI
107+
#### Flutter Extension for Gemini CLI
89108

90109
The [Flutter Extension for Gemini CLI][flutter-extension] combines the [Dart and
91110
Flutter MCP Server][dart-mcp-dart-docs] with rules and commands. It uses the
@@ -105,7 +124,7 @@ the [README][flutter-extension].
105124
[flutter-extension]: {{site.github}}/gemini-cli-extensions/flutter
106125
[flutter-extension-blog]: https://blog.flutter.dev/meet-the-flutter-extension-for-gemini-cli-f8be3643eaad
107126

108-
## Dart and Flutter MCP Server
127+
### Dart and Flutter MCP Server
109128

110129
To provide assistance during Flutter development, AI tools
111130
need to communicate with Dart and Flutter's developer tools.
@@ -127,7 +146,7 @@ on dart.dev and the [Dart and Flutter MCP repository][dart-mcp-github].
127146
[dart-mcp-github]: {{site.github}}/dart-lang/ai/tree/main/pkgs/dart_mcp_server
128147
[dart-mcp-flutter-docs]: #dart-and-flutter-mcp-server
129148

130-
## Rules for Flutter and Dart
149+
### Rules for Flutter and Dart
131150

132151
You can use a rules file with AI-powered editors to provide
133152
context and instructions to an underlying LLM. To get

src/content/ai/genui/components.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
title: Main components and concepts
3+
description: >-
4+
Familiarize yourself with the main components and concepts of the
5+
Flutter for GenUI SDK.
6+
---
7+
8+
:::experimental
9+
The `genui` package is in
10+
alpha and is likely to change.
11+
:::
12+
13+
## Main components
14+
15+
The package is built around the following main components:
16+
17+
* `GenUiConversation`: The primary facade and entry point for the package.
18+
It includes the `GenUiManager` and `ContentGenerator` classes,
19+
manages the conversation history,
20+
and orchestrates the entire generative UI process.
21+
22+
* `Catalog`: A collection of `CatalogItem` objects that defines
23+
the set of widgets that the AI is allowed to use.
24+
Each `CatalogItem` specifies a widget's name (for the AI
25+
to reference), a data schema for its properties, and a
26+
builder function to render the Flutter widget.
27+
28+
* `DataModel`: A centralized, observable store for all dynamic UI state.
29+
Widgets are _bound_ to data in this model. When data changes,
30+
only the widgets that depend on that specific piece of data are rebuilt.
31+
32+
* `ContentGenerator`: An interface for communicating with a generative AI model.
33+
This interface uses streams to send `A2uiMessage` commands,
34+
text responses, and errors back to the `GenUiConversation`.
35+
36+
* `A2uiMessage`: A message sent from the AI
37+
(through the `ContentGenerator`) to the UI,
38+
instructing it to perform actions like `beginRendering`,
39+
`surfaceUpdate`, `dataModelUpdate`, or `deleteSurface`.
40+
41+
## How it works
42+
43+
The `GenUiConversation` manages the interaction cycle:
44+
45+
1. **User input**: The user provides a prompt (for example, through a text field).
46+
The app calls `genUiConversation.sendRequest()`.
47+
2. **AI invocation**: The `GenUiConversation` adds the user's message to its
48+
internal conversation history and calls `contentGenerator.sendRequest()`.
49+
3. **AI response**: The `ContentGenerator` interacts with the AI model.
50+
The AI, guided by the widget schemas, sends back responses.
51+
4. **Stream handling**: The `ContentGenerator` emits A2uiMessages,
52+
text responses, or errors on its streams.
53+
5. **UI state update**: `GenUiConversation` listens to these streams.
54+
`A2uiMessages` are passed to `GenUiManager.handleMessage()`,
55+
which updates the UI state and `DataModel`.
56+
6. **UI rendering**: The `GenUiManager` broadcasts an update,
57+
and any `GenUiSurface` widgets listening for that surface ID will rebuild.
58+
Widgets are bound to the `DataModel`, so they update automatically
59+
when their data changes.
60+
7. **Callbacks**: Text responses and errors trigger the `onTextResponse`
61+
and `onError` callbacks on `GenUiConversation`.
62+
8. **User interaction**: The user interacts with the newly generated UI
63+
(for example, by typing in a text field). This interaction directly
64+
updates the `DataModel`. If the interaction is an action (like a button click),
65+
the `GenUiSurface` captures the event and forwards it to the
66+
`GenUiConversation`'s `GenUiManager`, which automatically creates
67+
a new `UserMessage` containing the current state of the data model
68+
and restarts the cycle.
69+
70+
For more detailed information on the implementation of GenUI SDK for Flutter,
71+
check out the [design doc][].
72+
73+
The next section walks you through adding `genui` to your app.
74+
75+
[design doc]: {{site.repo.organization}}/genui/blob/main/packages/genui/DESIGN.md
76+
[`genui`]: {{site.pub-pkg}}/genui

0 commit comments

Comments
 (0)