Render in Flutter
The same answers, drawn natively on iOS, Android and the web.
Install
Section titled “Install”dependencies: val_genui_flutter: path: vendor/sdk/val_genui_flutterDraw a reply
Section titled “Draw a reply”import 'package:val_genui_flutter/val_genui_flutter.dart';import 'package:http/http.dart' as http;
final request = http.Request('POST', Uri.parse('$backend/chat')) ..headers.addAll(genUiHeaders()) ..body = question;final response = await client.send(request);
GenUiReplyView( events: readEvents(response.stream), onAction: (action) => send(actionMessage(action)),)events takes any Stream: readEvents(response.stream) for HTTP (SSE, or ndjson: true), a WebSocket’s messages, or ui.events when the agent runs in the app. For your own layout, GenUiPartView(part: part, onAction: …) draws one part.
Errors
Section titled “Errors”A refusal carries the service’s own words — hand it back to the model and it fixes its call.
final result = await genui.invoke(call);if (!result.ok) { // refused: switch on result.error!.code, never on the message}// result.forModel goes back to the model either wayinvoke returns a refusal as a result rather than throwing; it throws only on a network failure or a 5xx from the service.
A 404 saying “has not been published yet” means the component exists but no version is live. Publish it.
Dart backends
Section titled “Dart backends”A Dart backend or agent without Flutter uses val_genui the same way — path: vendor/sdk/val_genui in pubspec.yaml.