A model can suggest a useful interface, but your application should decide which widgets and actions are allowed. GenUI coordinates model interaction with an existing widget catalog; it does not mean executing arbitrary Dart source returned by a model.
Know the current boundary
The GenUI SDK overview describes a JSON-based UI orchestration layer. The package is experimental and its APIs can change. Pin the version used by your project and follow that version’s setup rather than assuming every example on the web is compatible.
Before integrating the SDK, practise the validation boundary with a tiny schema you control. The following example is plain Dart/Flutter application logic, not a GenUI protocol implementation.
Parse only an approved shape
class SuggestedLesson {
const SuggestedLesson(this.title, this.lessonId);
final String title;
final String lessonId;
static SuggestedLesson? parse(Object? input, Set<String> allowedIds) {
if (input is! Map<String, dynamic>) return null;
if (input['type'] != 'lesson_card') return null;
final title = input['title'];
final id = input['lessonId'];
if (title is! String || id is! String) return null;
final cleanTitle = title.trim();
if (cleanTitle.isEmpty || cleanTitle.length > 100) return null;
if (!allowedIds.contains(id)) return null;
return SuggestedLesson(cleanTitle, id);
}
}
The app controls the allowed lesson identifiers. The model supplies a suggestion, not an arbitrary URL or a method name. A failed parse returns no approved card; the UI can show a normal text fallback and a retry action.
Render from your own catalog
After parsing, build a Card or ListTile using your application theme. Its button should navigate through the existing router using the approved lessonId. It should not launch an unvalidated external link copied from the model response.
If a response needs a destructive action, use an ordinary confirmation flow and enforce authorization in the service that performs the operation. A widget catalog alone is not an authorization system.
Add the orchestration layer afterward
Once the simple boundary is tested, map the same constraints into the catalog and message handling supported by your selected GenUI version. Keep model transport separate from navigation and domain services. Record whether an incoming response was rejected because of syntax, an unsupported component or an unavailable action.
Test inputs that should fail
Try a missing title, a very long title, a numeric identifier, an unknown lesson and an unsupported component type. Confirm that none crashes the screen or creates an unintended action. Then test an allowed card with a valid title and verify keyboard activation and focus labels.
Exercise
Add one optional subtitle while keeping the schema explicit. Write tests for a valid response and three rejected responses. Explain how you would provide an understandable fallback if the model returns an interface your client version does not support.