Main components and concepts
Main components
#The package is built around the following main components:
-
GenUiConversation: The primary facade and entry point for the package. It includes theGenUiManagerandContentGeneratorclasses, manages the conversation history, and orchestrates the entire generative UI process. -
Catalog: A collection ofCatalogItemobjects that defines the set of widgets that the AI is allowed to use. EachCatalogItemspecifies a widget's name (for the AI to reference), a data schema for its properties, and a builder function to render the Flutter widget. -
DataModel: A centralized, observable store for all dynamic UI state. Widgets are bound to data in this model. When data changes, only the widgets that depend on that specific piece of data are rebuilt. -
ContentGenerator: An interface for communicating with a generative AI model. This interface uses streams to sendA2uiMessagecommands, text responses, and errors back to theGenUiConversation. -
A2uiMessage: A message sent from the AI (through theContentGenerator) to the UI, instructing it to perform actions likebeginRendering,surfaceUpdate,dataModelUpdate, ordeleteSurface.
How it works
#The GenUiConversation manages the interaction cycle:
-
User input: The user provides a prompt (for example, through a text field).
The app calls
genUiConversation.sendRequest(). -
AI invocation: The
GenUiConversationadds the user's message to its internal conversation history and callscontentGenerator.sendRequest(). -
AI response: The
ContentGeneratorinteracts with the AI model. The AI, guided by the widget schemas, sends back responses. -
Stream handling: The
ContentGeneratoremits A2uiMessages, text responses, or errors on its streams. -
UI state update:
GenUiConversationlistens to these streams.A2uiMessagesare passed toGenUiManager.handleMessage(), which updates the UI state andDataModel. -
UI rendering: The
GenUiManagerbroadcasts an update, and anyGenUiSurfacewidgets listening for that surface ID will rebuild. Widgets are bound to theDataModel, so they update automatically when their data changes. -
Callbacks: Text responses and errors trigger the
onTextResponseandonErrorcallbacks onGenUiConversation. -
User interaction: The user interacts with the newly generated UI
(for example, by typing in a text field). This interaction directly
updates the
DataModel. If the interaction is an action (like a button click), theGenUiSurfacecaptures the event and forwards it to theGenUiConversation'sGenUiManager, which automatically creates a newUserMessagecontaining the current state of the data model and restarts the cycle.
For more detailed information on the implementation of GenUI SDK for Flutter, check out the design doc.
The next section walks you through adding genui to your app.
Unless stated otherwise, the documentation on this site reflects Flutter 3.38.1. Page last updated on 2025-11-18. View source or report an issue.