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_genuiframework. By introducing a dedicatedUserActionEventwith 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
UiActionEventwith a more structuredUserActionEvent. This new event type now explicitly includesactionName,sourceComponentId, and a flexiblecontextmap for data binding.UserActionEvent'scontextnow supports data binding, allowing values to be resolved from theDataContextusing paths, or provided as literal strings, numbers, or booleans. A newresolveContextutility function has been introduced to facilitate this.GenUiManager'shandleUiEventmethod has been updated to correctly process the newUserActionEventformat. It now constructs aUserMessagewith 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 newUserActionEventand its associatedactionschema, 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
CatalogGalleryAppto aStatefulWidgetto manage state.onSubmitcallback toDebugCatalogViewto display user actions as snackbar messages._sendMessageto returnvoidand usedunawaitedfor_uiAgent.sendRequestto handle asynchronous operations without awaiting.DateInputChip,ListingsBooker,PaddedBodyText,SectionHeader, andTabbedSections.actionproperty to the_InputGroupDataschema and factory.ElevatedButton'sonPressedhandler to dispatch aUserActionEventwith a resolved context.choiceRequiredActionproperty to the_ItineraryEntryDataschema and factory.FilledButton'sonPressedto dispatch aUserActionEventwith a resolved context.borderRadiusinClipRRect.modifyActionproperty to the_ListingsBookerDataschema and factory.TextButton'sonPressedto dispatch aUserActionEventwith a resolved context, including thelistingSelectionId.actionproperty to the_TrailheadDataschema and factory.InputChip'sonPressedto dispatch aUserActionEventwith a resolved context, including the selectedtopic.actionproperty to the_TravelCarouselItemSchemaDataschema and factory.InkWell'sonTapto dispatch aUserActionEventwith a resolved context, includingdescriptionandlistingSelectionId.actionfield.actionfield.UiActionEventtoUserActionEventand verifiedactionNameandsourceComponentId.actionfield.UiActionEventtoUserActionEventand verifiedactionNameandcontext.actionfield.UiActionEventtoUserActionEventand verifiedactionNameandcontext.ChatMessagedescription to includeUserUiInteractionMessage.UiAgentinitialization and event dispatch steps in the data flow.onEventcallback from theGenUiSurfaceexample, as event handling is now managed differently.Columnwidget definition to use the newactionformat forElevatedButton.actionproperty in the schema from a simple string toGulfSchemas.actionfor structured event data.ElevatedButton'sonPressedhandler to dispatch aUserActionEventwith a resolved context.exampleDatafor better demonstration and testing.onSubmittedActionproperty to the_TextFieldDataschema and factory.onSubmittedcallback to dispatch aUserActionEventwith a resolved context.handleUiEventto specifically processUserActionEventinstances.UserMessagewith a JSON payload containing detailed user action information and the current UI state._dispatchEventto correctly castUserActionEventwhen re-creating the event with thesurfaceId.resolveContextutility function to resolve data-bound context definitions from aDataContext.actionschema to useactionName(string) andcontext(object with data-bound properties) instead of a singleactionstring and a list of key-value pairs.UiActionEventtoUserActionEvent.widgetId,eventType, andvaluetoactionName,sourceComponentId, andcontext.ElevatedButtonandTextFieldto includeactionandonSubmittedActionrespectively.handleUiEventto verify the correct processing ofUserActionEventand the creation ofUserMessage.ElevatedButtonto include the newactionfield.UiEventtoUserActionEvent.UserActionEvent(actionName,sourceComponentId,context).Related Issues