Skip to content

Conversation

@jacobsimionato
Copy link
Collaborator

This PR refactors the custom_backend example to fully align with the A2UI streaming protocol specification.

Key changes include:

  • Protocol Compliance: The app no longer uses a custom uiGenerator tool. It now correctly generates a surfaceUpdate tool call that conforms to the official A2uiSchemas.surfaceUpdateSchema.
  • A2UI Message Parsing: The response from the LLM is now parsed into a strongly-typed A2uiMessage object using the A2uiMessage.fromJson factory.
  • BeginRendering Implementation: A BeginRendering message is now synthetically created and sent to the GenUiManager after the SurfaceUpdate message, correctly following the A2UI progressive rendering flow.
  • Constant surfaceId: A constant kSurfaceId has been introduced to ensure consistency across the prompt, UI, and message creation.
  • Testing: The tests have been updated to validate the new A2UI-compliant message flow. The saved test responses have been updated with real data captured from the Gemini API.
  • Cleanup: Removed the unused widget_test.dart file.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a solid refactoring that aligns the custom_backend example with the A2UI protocol specification. The transition from the custom uiGenerator to the standard surfaceUpdate tool, along with parsing responses into A2uiMessage objects and introducing the BeginRendering message, significantly improves protocol compliance and code structure. The tests have also been thoughtfully updated to reflect these changes. My review includes a few minor suggestions to enhance debugging practices and improve the user experience.

Comment on lines 96 to 99
print('No UI received.');
_surfaceId = null;
setState(() {
_isLoading = false;
_errorMessage = null;
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When no UI is received from the backend, the app currently prints a message to the console and shows a blank space to the user. It would be a better user experience to display a message on the screen. You can achieve this by setting the _errorMessage in the state.

Suggested change
print('No UI received.');
_surfaceId = null;
setState(() {
_isLoading = false;
_errorMessage = null;
});
setState(() {
_isLoading = false;
_errorMessage = 'No UI received from the backend.';
});

return const Text('No UI 🤷‍♀️');
}
return GenUiSurface(surfaceId: _surfaceId!, host: _genUi);
return GenUiSurface(surfaceId: kSurfaceId, host: _genUi);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This change removes the initial 'No UI 🤷‍♀️' message, showing a blank area instead. This might be confusing for users. To restore the original behavior and provide better feedback, you can use the defaultBuilder property of GenUiSurface.

Suggested change
return GenUiSurface(surfaceId: kSurfaceId, host: _genUi);
return GenUiSurface(surfaceId: kSurfaceId, host: _genUi, defaultBuilder: (context) => const Text('No UI 🤷‍♀️'));

@jacobsimionato jacobsimionato changed the title refactor(custom_backend): Align with A2UI protocol Refactor the custom backend to work with A2UI-based schema Oct 21, 2025
}

const _title = 'Custom Backend Demo';
const kSurfaceId = 'custom_backend_surface';
Copy link
Collaborator

@polina-c polina-c Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using prefix 'k' is debatable, that means not everyone will follow this code style.

flutter/flutter#20858

this tradition is very old and came from C:

"c" was the tag for type "char", so it couldn't also be used for "const"; so "k" was chosen, since that's the first letter of "konstant" in German, and is widely used for constants in mathematics

https://stackoverflow.com/questions/5016622/where-does-the-k-prefix-for-constants-come-from

How about declaring genui traditions for debatable things in some central Coding Style document in the repo, to make it clear for all developers?

Added a constant for the surface ID in the Protocol class.
@polina-c polina-c merged commit 8b7ad6a into flutter:main Oct 21, 2025
14 checks passed
gspencergoog pushed a commit to gspencergoog/genui that referenced this pull request Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants