This application is a minimal example of how to use the genui package to create a simple, conversational chat application.
The main goal of this example is to demonstrate the fundamental concepts of genui in a straightforward chat context. It shows how to:
- Initialize and use the
SurfaceController, the core engine for the package. - Provide a simple system prompt to guide the AI's behavior.
- Send user messages to the AI and receive responses.
- Handle the creation of new UI "surfaces" generated by the AI.
- Render these dynamic UI surfaces within a standard chat message list.
- Manage a conversation history that interleaves user text messages with AI-generated UI responses.
Unlike more complex examples, this app does not define a custom widget catalog. Instead, it relies on the default coreCatalog provided by genui, meaning the AI can only respond with basic widgets like Text, Column, ElevatedButton, etc.
The application's logic is contained almost entirely within lib/chat_session.dart.
- Initialization: A
SurfaceControlleris created to manage the state of UI surfaces. - User Input: The user types a message into a
TextFieldand hits send. - Sending the Message:
- The user's text is immediately added to the local message list.
- The request is sent to the
AiClient.
- AI Response:
- The
AiClientstreamsA2uiMessages back. - These messages are piped into the
SurfaceController.
- The
- UI Rendering:
- The UI listens to
SurfaceController.surfaceUpdatesorA2uiTransportAdapterstreams. - When a surface is added, a
Surfacewidget is rendered, dynamically building the UI based on theUiDefinitionmanaged bySurfaceController.
- The UI listens to
Follow the instructions in the run_app_with_gemini_key.md.