Skip to content
Talk to an engineerRequest access

Render in Flutter

The same answers, drawn natively on iOS, Android and the web.

  • ⏱ 10 minutes
  • Tested on Flutter 3.47
pubspec.yaml
dependencies:
val_genui_flutter:
path: vendor/sdk/val_genui_flutter
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.

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 way

invoke 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.

A Dart backend or agent without Flutter uses val_genui the same way — path: vendor/sdk/val_genui in pubspec.yaml.