A widget that can render a JSON protocol with a catalog and separate state. #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces the initial, feature-complete implementation of the
fcp_clientpackage, a client-side library for the Flutter Composition Protocol (FCP).This package allows a Flutter application to render and manage a user interface based on JSON payloads sent from a server, strictly following the protocol defined in the project's documentation. The implementation was developed following the detailed plan in
docs/FCP Implementation Plan.md.Here's the summary of the protocol:
Features Implemented
This PR delivers the full feature set specified in the FCP documentation, covering all 5 implementation milestones:
Milestone 1: Core Models & Static Rendering
DynamicUIPacket,WidgetNode, etc.) implemented using Dartextension typesfor type safety without code generation.FcpView) that can parse the non-recursive node list and render a static Flutter widget tree.CatalogServicefor loading the client's capabilities catalog and aWidgetCatalogRegistryfor mapping widget types to builders.Milestone 2: State Management & Data Binding
FcpStatemanager (ChangeNotifier) to hold dynamic UI data.BindingProcessorservice that resolves data paths and applies declarative transformations (format,condition,map).Milestone 3: Event Handling
FcpViewexposes anonEventcallback to send user interactions to a backend.EventPayload, including contextual arguments.Milestone 4: Targeted Updates
StateUpdatepayloads using thejson_patchstandard to efficiently update theFcpStateobject.LayoutUpdatepayloads (add,remove,update) to make surgical changes to the UI's structure.FcpViewControllerprovides a clean, stream-based API for dispatching both state and layout updates to theFcpView.Milestone 5: Advanced Features & Refinement
ListView.builderfor efficiently rendering dynamic lists, including support for scopeditem.bindings.json_schemapackage to validate incoming state against schemas defined in theWidgetCatalog.Key Architectural Decisions & Learnings
The development journey, chronicled in
docs/JOURNEY.md, led to several key decisions and learnings that shaped the final architecture:test_fixtures/m1_integration), which is the correct pattern for testing a Flutter package.ChangeNotifieritself. It now passes aMapof named children (e.g.,appBar,body) to widget builders instead of a flat list, making builders more robust and less prone to ordering errors.///) to ensure the package is easy for developers to understand and use.Testing
The package has extensive test coverage:
BindingProcessor,LayoutPatcher,StatePatcher, andDataTypeValidatorare thoroughly tested. All data models are also validated.FcpViewis tested for rendering, event handling, state/layout updates, error handling, and theListViewBuilder.test_fixtures/m1_integrationverifies the end-to-end functionality in a running application.All 74 tests pass, ensuring the package is stable and correct.