Skip to content

feat(craft): add the Flutter building blocks - #57

Open
innkuika wants to merge 2 commits into
craft/event-argsfrom
craft/building-blocks
Open

innkuika wants to merge 2 commits into
craft/event-argsfrom
craft/building-blocks

Conversation

@innkuika

@innkuika innkuika commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Description

Adds craft/packages/a2ui_craft_building_blocks: the building blocks templates draw with on Flutter, so a host can render real templates without writing its own primitives. Stacked on #56 (stack #51).

  • Blocks: Row, Column, Stack, Box, ScrollView, Grid, LazyList, Text, Image, Icon, Divider, Button, TextInput, Checkbox, Switch, Radio, Slider, Select, DatePicker, as a PrimitiveWidgetLibrary for a2ui_craft_flutter. Each block's metadata gives its arguments' kinds, so A2UI schema derivation works for templates that use it.
  • Blueprint: craft/blueprints/features/craft_building_blocks.blueprint.md. It specifies each block's arguments, value formats, events and payloads, accessibility, and the layout rules that matter for cross-platform parity:
    • Row and Column follow CSS flex semantics: children shrink and text wraps rather than overflowing, growing boxes share the remaining space with min/max clamping, and Column fills its width by default;
    • start/end alignment, so layout follows the ambient text direction (left-to-right and right-to-left);
    • Box(clip: true) clips to rounded corners;
    • LazyList builds only visible items, keyed by item id, and reports duplicate or missing ids to the host.
  • Controls: disabled when their handler does nothing; keyboard- and screen-reader-accessible; they grow with text scale. Toggles show their label when one is given.
  • Small change below: PrimitiveArguments.reportError in a2ui_craft_flutter, so a block can report argument errors through the view's onError.
  • CI: a step compiles a small app using the blocks for the web (JS and Wasm).
  • Tests: 203 widget tests, covering layout geometry in logical pixels (including RTL and text scaling), event payloads, disabled states, semantics, LazyList laziness, and a flight card and a settings form rendered on a real A2UI surface.
  • Each block is a plain function over a small BlockArgs interface, so the blocks can be wrapped as A2UI component implementations later (Determine if and how Craft templates should be built on top of the existing Catalog API a2ui#4484) without rewriting them.

Value types, the Grid formula and Box's border-box model come from Yegor's prototype, hence the co-author. An independent review covered the spec, tests, accessibility and the flex algorithm against hand-computed CSS layouts.

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 2, 2026 22:16
@innkuika
innkuika added this pull request to stack #51 December 2, 2026 22:16

@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 a2ui_craft_building_blocks package, which implements nineteen core layout, content, and control primitives as Flutter widgets according to the new craft_building_blocks feature blueprint. It also integrates primitive argument error reporting (PrimitiveArgumentError) into the Flutter adapter and template catalog renderer, backed by a comprehensive suite of widget tests. The review feedback recommends enhancing the usability of toggle labels by setting HitTestBehavior.opaque on their GestureDetector, and improving robustness in DatePicker by checking context.mounted after the asynchronous date picker dialog is dismissed.

Comment on lines +344 to +347
child: GestureDetector(
onTap: onTap,
excludeFromSemantics: true,
child: Text(

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

By default, GestureDetector only registers hit tests on its visible child (the text characters). Setting behavior: HitTestBehavior.opaque ensures that the entire bounding box of the label is tappable, making it much easier for users to toggle the control on mobile devices.

Suggested change
child: GestureDetector(
onTap: onTap,
excludeFromSemantics: true,
child: Text(
child: GestureDetector(
onTap: onTap,
behavior: HitTestBehavior.opaque,
excludeFromSemantics: true,
child: Text(

firstDate: first,
lastDate: last,
);
if (picked != null) onChanged!(encodeDate(picked));

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

After an asynchronous gap (like awaiting showDatePicker), it is a best practice in Flutter to check if the BuildContext is still mounted before calling callbacks or interacting with the widget tree. This prevents potential issues if the widget was unmounted while the date picker dialog was open.

Suggested change
if (picked != null) onChanged!(encodeDate(picked));
if (picked != null && context.mounted) onChanged!(encodeDate(picked));

innkuika and others added 2 commits December 3, 2026 11:00
Adds the core building blocks that templates compose, as a new package,
a2ui_craft_building_blocks, with the feature blueprint
craft_building_blocks:

- Nineteen blocks as a PrimitiveWidgetLibrary for a2ui_craft_flutter:
  Row, Column, Stack, Box, ScrollView, Grid and LazyList; Text, Image,
  Icon and Divider; Button, TextInput, Checkbox, Switch, Radio, Slider,
  Select and DatePicker. Each block's metadata gives the kind of each
  argument, so templates that use them get typed A2UI schemas.
- Each block is a plain function of a BlockArgs interface, so another
  adapter (such as A2UI component properties) can reuse it unchanged.
- One sizing model (hug, fill with natural sizes, fixed, clamps), a Row
  and Column layout of its own (in a Row every child but fixed sizes
  shrinks in proportion to its width, as CSS's default flex item; flex
  Boxes take the rest, clamped by CSS's rule), an auto-fit Grid, all
  specified in logical pixels for parity with a CSS renderer. Alignments and insets
  follow the reading direction (start and end), and the layout mirrors in
  a right-to-left host. A Column fills its width by default; Box can clip.
- LazyList builds only the items in view and keys each by its id, for
  both template state and widget state; unusable ids are reported to the
  host through the new PrimitiveArguments.reportError, which CraftView
  forwards to onError as a PrimitiveArgumentError.
- Controls: disabled without a runnable handler, visible toggle labels
  that toggle, keyboard-focusable and assistive-technology-activatable
  DatePicker, exact Slider step values announced as values, fields that
  grow with the text scale.
- Widget tests per block (sizes and positions in both reading
  directions, events and their arguments, disabled states, semantics,
  keyboard focus, scaled text, an image still loading), the blocks and
  kinds checked against the blueprint's table, and a flight card and a
  settings form rendered through templateCatalog on an A2UI surface.
- The codebase blueprints' format recipe is scripts/fix_format.sh, which
  CI checks.
- CI compiles a small web app that uses the blocks with dart2js and
  dart2wasm.
- Feature registry entries F-CRAFT-BLOCKS-01..09, covered by the widget
  tests.

Ported from the prototype's primitives: the value formats (Yegor's value
types), Grid's auto-fit formula and Box's border-box model (Yegor's
layout primitives), the control sizes, the text styles of its default
theme and the icon names of the A2UI basic catalog, rewritten against the
labs API without theme roles. LazyList, the Row and Column layout, the
reading-direction model and Box clipping are new.

Co-authored-by: Yegor <yegor.jbanov@gmail.com>
@innkuika
innkuika force-pushed the craft/building-blocks branch from 886f8d5 to 6014ec8 Compare December 3, 2026 19:00
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