Skip to content

docs(craft): getting started, language reference, example app - #60

Open
innkuika wants to merge 1 commit into
craft/incrementalfrom
craft/examples
Open

innkuika wants to merge 1 commit into
craft/incrementalfrom
craft/examples

Conversation

@innkuika

@innkuika innkuika commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Description

Adds the getting-started docs and an example app for the Craft Flutter developer preview. Stacked on #59 (stack #51).

  • craft/docs/getting-started.md: add Craft to a Flutter app (git dependencies pinned to a full commit hash, since the packages depend on each other by path), register the building blocks and a template library, wire templateCatalog into an a2ui_flutter surface, write a first template, load a binary, and handle errors and limits.
  • craft/docs/language.md: an author's reference to the Craft language as it is in the stack, with each section linked to the blueprint that specifies it exactly.
  • craft/docs/status.md: what's in and out of the preview, and its known limitations: Flutter only, theme references undefined, no reactive write-back yet, state follows position, and the upcoming Node API change (Determine if and how Craft templates should be built on top of the existing Catalog API a2ui#4484) and what it changes for hosts versus template authors.
  • craft/examples/flutter_app/: an A2UI surface with the template catalog, the building blocks and a scripted fake agent. It has three screens:
    • a flight status card (status colors, local expand state, an action to the agent, responsive layout);
    • a settings page (two-way bound controls, the agent's checks, a confirm step using event arguments);
    • an access-request form with cross-field rules (lock-and-clear, conditional visibility and required fields, validation with the new text, regex, number and date functions). This form's library is loaded from downloaded binary bytes.
  • Tests (66): end-to-end widget tests per screen, a check that every template parses and registers against the shipped building blocks, and doc tests. Every Craft snippet in the docs is rendered, every table row in language.md is evaluated, and the guide's app is built from the doc's snippets alone in a fresh project (git dependencies via a file:// URL), then analyzed and tested.
  • The Presubmit Craft analyze step now also covers craft/examples/.

An independent review followed the guide literally as a first-time developer and checked language.md against the blueprints.

Pre-launch Checklist

  • I signed the CLA.
  • I read the Contributors Guide.
  • I updated/added relevant documentation.
  • My code changes (if any) have tests.
  • License checks pass (python3 ./scripts/fix_licenses.py --check).
  • Format checks pass (./scripts/fix_format.sh --check).

@innkuika
innkuika requested a review from ditman December 3, 2026 00:36
@innkuika
innkuika added this pull request to stack #51 December 3, 2026 00:36

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

Copy link
Copy Markdown

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 introduces the Craft developer preview, including comprehensive documentation and a realistic Flutter example app with three screens (Flight, Settings, and Request) to demonstrate template rendering, local state, and agent integration. The review feedback suggests defensively handling potentially null surfaces in app.dart to avoid runtime crashes, and resolving raw type warnings for Map checks in fake_agent.dart and template_lint.dart to comply with the enabled strict-raw-types analyzer rule.

Comment on lines +130 to +141
Widget build(BuildContext context) {
final (String surfaceId, String title, _) = ExampleScreens.screens[_index];
return Scaffold(
appBar: AppBar(title: Text(title)),
body: SingleChildScrollView(
key: PageStorageKey<String>(surfaceId),
padding: const EdgeInsets.all(16),
child: A2uiSurface(
key: ValueKey<String>(surfaceId),
surface: widget.host.processor.model.getSurface(surfaceId)!,
),
),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using the null assertion operator ! on getSurface(surfaceId) can lead to a runtime crash if the surface is not yet available (e.g., if the agent hasn't finished processing the createSurface message or if there was an initialization delay). It is safer to handle the null case defensively by showing a loading indicator or fallback widget.

Suggested change
Widget build(BuildContext context) {
final (String surfaceId, String title, _) = ExampleScreens.screens[_index];
return Scaffold(
appBar: AppBar(title: Text(title)),
body: SingleChildScrollView(
key: PageStorageKey<String>(surfaceId),
padding: const EdgeInsets.all(16),
child: A2uiSurface(
key: ValueKey<String>(surfaceId),
surface: widget.host.processor.model.getSurface(surfaceId)!,
),
),
Widget build(BuildContext context) {
final (String surfaceId, String title, _) = ExampleScreens.screens[_index];
final surface = widget.host.processor.model.getSurface(surfaceId);
return Scaffold(
appBar: AppBar(title: Text(title)),
body: surface == null
? const Center(child: CircularProgressIndicator())
: SingleChildScrollView(
key: PageStorageKey<String>(surfaceId),
padding: const EdgeInsets.all(16),
child: A2uiSurface(
key: ValueKey<String>(surfaceId),
surface: surface,
),
),
);

Comment on lines +80 to +81
final Object? settings = action.context['settings'];
final Object? digest = settings is Map ? settings['digest'] : null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Since strict-raw-types is enabled in analysis_options.yaml, using the raw type Map in the type check settings is Map will trigger a raw type warning. Specifying the type arguments, such as Map<Object?, Object?>, resolves this warning and ensures type safety.

Suggested change
final Object? settings = action.context['settings'];
final Object? digest = settings is Map ? settings['digest'] : null;
final Object? settings = action.context['settings'];
final Object? digest = settings is Map<Object?, Object?> ? settings['digest'] : null;

Comment on lines +85 to +87
case 'submitForm':
final Object? request = action.context['request'];
final Object? count = request is Map ? request['count'] : null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Since strict-raw-types is enabled in analysis_options.yaml, using the raw type Map in the type check request is Map will trigger a raw type warning. Specifying the type arguments, such as Map<Object?, Object?>, resolves this warning and ensures type safety.

Suggested change
case 'submitForm':
final Object? request = action.context['request'];
final Object? count = request is Map ? request['count'] : null;
case 'submitForm':
final Object? request = action.context['request'];
final Object? count = request is Map<Object?, Object?> ? request['count'] : null;

Comment on lines +50 to +54
for (final String arg in arguments.keys) {
if (params is! Map || !params.containsKey(arg)) {
problems.add('$where takes no argument $arg');
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Since strict-raw-types is enabled in analysis_options.yaml, using the raw type Map in the type check params is! Map will trigger a raw type warning. Specifying the type arguments, such as Map<Object?, Object?>, resolves this warning and ensures type safety.

Suggested change
for (final String arg in arguments.keys) {
if (params is! Map || !params.containsKey(arg)) {
problems.add('$where takes no argument $arg');
}
}
for (final String arg in arguments.keys) {
if (params is! Map<Object?, Object?> || !params.containsKey(arg)) {
problems.add('$where takes no argument $arg');
}
}

@innkuika
innkuika force-pushed the craft/examples branch 2 times, most recently from 9e30b84 to b2fa725 Compare December 3, 2026 19:00
Adds the docs and the example of the Flutter developer preview:

- craft/docs/getting-started.md: add Craft to a Flutter app with git
  dependencies, register the building blocks and a template library, make
  a template catalog for an a2ui_flutter surface, write a first template,
  ship templates as assets or binary blobs, handle errors and limits.
- craft/docs/language.md: the template language for authors, each section
  linked to the blueprint that specifies it, with a table of every standard
  function and an example of each.
- craft/docs/status.md: what the preview has and lacks, known limitations,
  and what a2ui-project/a2ui#4484 would change for hosts and for authors.
- craft/examples/flutter_app: an app with a flight status card, a settings
  page and an access request form with cross-field rules, written as .craft
  libraries (three loaded from assets, one decoded from downloaded bytes)
  and driven by a scripted agent; widget tests for each screen, a check of
  every library against the building blocks, and tests that run every
  snippet of the docs.
- craft/README.md points to the docs and the example; Presubmit Craft also
  analyzes the examples.
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.

1 participant