Migrate UI events to use new format. #370
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Convert user events to use userAction.
Summary of Changes
This pull request significantly refactors the way user interactions are handled within the
flutter_genui
framework. By introducing a dedicatedUserActionEvent
with explicit action names and a flexible, data-bound context, it standardizes and enriches the information passed from the UI to the AI. This change improves the clarity and robustness of event processing, with corresponding updates across examples, core widgets, and documentation to ensure a seamless transition to the new event format.Highlights
UiActionEvent
with a more structuredUserActionEvent
. This new event type now explicitly includesactionName
,sourceComponentId
, and a flexiblecontext
map for data binding.UserActionEvent
'scontext
now supports data binding, allowing values to be resolved from theDataContext
using paths, or provided as literal strings, numbers, or booleans. A newresolveContext
utility function has been introduced to facilitate this.GenUiManager
'shandleUiEvent
method has been updated to correctly process the newUserActionEvent
format. It now constructs aUserMessage
with a JSON payload that includes the detailed user action and the current state of the UI surface.ElevatedButton
,TextField
) and example applications (catalog_gallery
,simple_chat
,travel_app
) have been migrated to utilize the newUserActionEvent
and its associatedaction
schema, ensuring consistency across the framework.IMPLEMENTATION.md
,README.md
) have been updated to reflect the changes in the event handling architecture and the updated component catalog descriptions.Changelog
CatalogGalleryApp
to aStatefulWidget
to manage state.onSubmit
callback toDebugCatalogView
to display user actions as snackbar messages._sendMessage
to returnvoid
and usedunawaited
for_uiAgent.sendRequest
to handle asynchronous operations without awaiting.DateInputChip
,ListingsBooker
,PaddedBodyText
,SectionHeader
, andTabbedSections
.action
property to the_InputGroupData
schema and factory.ElevatedButton
'sonPressed
handler to dispatch aUserActionEvent
with a resolved context.choiceRequiredAction
property to the_ItineraryEntryData
schema and factory.FilledButton
'sonPressed
to dispatch aUserActionEvent
with a resolved context.borderRadius
inClipRRect
.modifyAction
property to the_ListingsBookerData
schema and factory.TextButton
'sonPressed
to dispatch aUserActionEvent
with a resolved context, including thelistingSelectionId
.action
property to the_TrailheadData
schema and factory.InputChip
'sonPressed
to dispatch aUserActionEvent
with a resolved context, including the selectedtopic
.action
property to the_TravelCarouselItemSchemaData
schema and factory.InkWell
'sonTap
to dispatch aUserActionEvent
with a resolved context, includingdescription
andlistingSelectionId
.action
field.action
field.UiActionEvent
toUserActionEvent
and verifiedactionName
andsourceComponentId
.action
field.UiActionEvent
toUserActionEvent
and verifiedactionName
andcontext
.action
field.UiActionEvent
toUserActionEvent
and verifiedactionName
andcontext
.ChatMessage
description to includeUserUiInteractionMessage
.UiAgent
initialization and event dispatch steps in the data flow.onEvent
callback from theGenUiSurface
example, as event handling is now managed differently.Column
widget definition to use the newaction
format forElevatedButton
.action
property in the schema from a simple string toGulfSchemas.action
for structured event data.ElevatedButton
'sonPressed
handler to dispatch aUserActionEvent
with a resolved context.exampleData
for better demonstration and testing.onSubmittedAction
property to the_TextFieldData
schema and factory.onSubmitted
callback to dispatch aUserActionEvent
with a resolved context.handleUiEvent
to specifically processUserActionEvent
instances.UserMessage
with a JSON payload containing detailed user action information and the current UI state._dispatchEvent
to correctly castUserActionEvent
when re-creating the event with thesurfaceId
.resolveContext
utility function to resolve data-bound context definitions from aDataContext
.action
schema to useactionName
(string) andcontext
(object with data-bound properties) instead of a singleaction
string and a list of key-value pairs.UiActionEvent
toUserActionEvent
.widgetId
,eventType
, andvalue
toactionName
,sourceComponentId
, andcontext
.ElevatedButton
andTextField
to includeaction
andonSubmittedAction
respectively.handleUiEvent
to verify the correct processing ofUserActionEvent
and the creation ofUserMessage
.ElevatedButton
to include the newaction
field.UiEvent
toUserActionEvent
.UserActionEvent
(actionName
,sourceComponentId
,context
).Related Issues