This application is a demonstration of the genui package, showcasing how to build a dynamic, conversational user interface powered by a generative AI model (like Google's Gemini).
The app functions as a travel planning assistant. Users can describe their desired trip, and the AI will respond by generating a rich, interactive UI to help them plan and refine their itinerary.
Instead of responding with text, the AI in this application communicates by building a user interface from a predefined catalog of Flutter widgets. The conversation flows as follows:
- User Prompt: The user starts by typing a request, such as "I want to plan a trip to Mexico."
- AI-Generated UI: The AI receives the prompt and, guided by its system instructions, generates a response in the form of UI elements. Initially, it might present a
travelCarouselof destinations andfilterChipGroupto ask clarifying questions about the user's budget, desired activities, or travel dates. - User Interaction: The user interacts with the generated UI (e.g., selects an option from a filter chip). These interactions are sent back to the AI as events.
- UI Refinement: The AI processes the user's selections and refines the plan, often by adding new UI elements to the conversation. For example, it might display a detailed
itinerary_with_detailswidget that outlines the proposed trip. - Continued Conversation: The AI may also present a
trailheadwidget with suggested follow-up questions (e.g., "Top culinary experiences," "Nightlife areas"), allowing the conversation to continue organically.
All of the UI is generated dynamically and streamed into a chat-like view, creating a seamless and interactive experience.
This example highlights several core concepts of the genui package:
- Dynamic UI Generation: The entire user interface is constructed on-the-fly by the AI based on the conversation.
- Component Catalog: The AI builds the UI from a custom, domain-specific catalog of widgets defined in
lib/src/catalog.dart. This includes widgets likeTravelCarousel,ItineraryEntry, andOptionsFilterChipInput. - System Prompt Engineering: The behavior of the AI is guided by a detailed system prompt located in
lib/src/travel_planner_page.dart. This prompt instructs the AI on how to act like a travel agent and which widgets to use in various scenarios. - Dynamic UI State Management: The
ConversationandSurfaceControllerfromgenuihandle the orchestration of AI interaction, state of the dynamically generated UI surfaces, and event processing. - Multiple AI Backends: The app supports switching between Google Generative AI (direct API) and Firebase Vertex AI. This is configured in
lib/src/config/configuration.dart. - Tool Use: The AI uses tools like
ListHotelsToolto fetch real-world data (mocked in this example) and present it to the user. - Widget Catalog: A dedicated tab allows developers to inspect all available widgets in the catalog, facilitating development and debugging.
This application can be run using either the Google Generative AI API directly (default) or Firebase Vertex AI.
Follow the instructions in the run_app_with_gemini_key.md.
To use Firebase, you need to configure the project and update the code.
- Configure Firebase: Follow the instructions in the main
genuipackage README.md to add Firebase to your Flutter app.- Set up a Firebase project.
- Generate
firebase_options.dartusingflutterfire configure.
- Update Configuration:
- Open
lib/src/config/configuration.dartand changeaiBackendtoAiBackend.firebase. - Open
lib/main.dartand uncomment the Firebase initialization code and imports (look forUNCOMMENT_FOR_FIREBASE).
- Open
- Run the App:
flutter run