Repository navigation
Conversation
There was a problem hiding this comment.
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.
| child: GestureDetector( | ||
| onTap: onTap, | ||
| excludeFromSemantics: true, | ||
| child: Text( |
There was a problem hiding this comment.
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.
| 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)); |
There was a problem hiding this comment.
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.
| if (picked != null) onChanged!(encodeDate(picked)); | |
| if (picked != null && context.mounted) onChanged!(encodeDate(picked)); |
070f7f8 to
886f8d5
Compare
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>
886f8d5 to
6014ec8
Compare
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).PrimitiveWidgetLibraryfora2ui_craft_flutter. Each block's metadata gives its arguments' kinds, so A2UI schema derivation works for templates that use it.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:Box(clip: true)clips to rounded corners;PrimitiveArguments.reportErrorina2ui_craft_flutter, so a block can report argument errors through the view'sonError.BlockArgsinterface, 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
python3 ./scripts/fix_licenses.py --check)../scripts/fix_format.sh --check).