Repository navigation
Conversation
There was a problem hiding this comment.
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.
| 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)!, | ||
| ), | ||
| ), |
There was a problem hiding this comment.
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.
| 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, | |
| ), | |
| ), | |
| ); |
| final Object? settings = action.context['settings']; | ||
| final Object? digest = settings is Map ? settings['digest'] : null; |
There was a problem hiding this comment.
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.
| 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; |
| case 'submitForm': | ||
| final Object? request = action.context['request']; | ||
| final Object? count = request is Map ? request['count'] : null; |
There was a problem hiding this comment.
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.
| 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; |
| for (final String arg in arguments.keys) { | ||
| if (params is! Map || !params.containsKey(arg)) { | ||
| problems.add('$where takes no argument $arg'); | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
| 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'); | |
| } | |
| } |
9e30b84 to
b2fa725
Compare
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.
b2fa725 to
f6293ec
Compare
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, wiretemplateCataloginto ana2ui_fluttersurface, 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:language.mdis evaluated, and the guide's app is built from the doc's snippets alone in a fresh project (git dependencies via afile://URL), then analyzed and tested.craft/examples/.An independent review followed the guide literally as a first-time developer and checked
language.mdagainst the blueprints.Pre-launch Checklist
python3 ./scripts/fix_licenses.py --check)../scripts/fix_format.sh --check).