jet_cad_2d_flutter
Flutter rendering and interaction for the pure-Dart
jet_cad_2d engine. It draws a
DraftDocument on a canvas, with a camera, rulers, selection and snapping,
and writes a page of it out as a vector PDF or a PNG. The engine stays free
of dart:ui; everything that needs Flutter is here.

What it holds
DraftCanvas: the widget that paints a document and repaints on camera and document changes and on nothing else.CameraControllerandViewportTransform: pan, zoom and the world-to-screen transform, with zoom-to-fit.RulerFrame: rulers around a canvas.InteractionLayerandToolController: the pointer layer over a canvas, which routes mouse, touch and keyboard input to the activeTool:SelectTool(selection and grips) or one of the drawing tools (LineTool,PolylineTool,RectangleTool,CircleTool,ArcTool,TextTool). Object snapping is configured withSnapSettingsand drawn bydrawSnapMarker.- PDF and PNG export:
exportPagePdfandexportPagePngwrite a page of a document to bytes.
Example
DraftCanvas borrows its document, its spatial index and its camera: the
application creates them and disposes of them. The document must carry a
FlutterTextMeasurer, which is how its text is measured. The snippet uses
both packages, so add both: dart pub add jet_cad_2d jet_cad_2d_flutter.
final document = DraftDocument.empty(measurer: FlutterTextMeasurer());
final index = SpatialIndex(document);
final camera = CameraController(
ViewportTransform.fit(document.extents.expandedBy(20), size));
final canvas = DraftCanvas(document: document, index: index, camera: camera);
A complete app, which draws a line and a circle and frames them, is
example/lib/main.dart.
Run it from the package directory with flutter run -t example/lib/main.dart.
Screenshots

The same drawing on the dark canvas: canvasResolverFor and ChromePalette.dark re-tone the colours for a dark theme.

A few entities selected, each with its grips, and one entity highlighted under the pointer.

A crossing band, dragged right to left, mid-drag: it selects what it touches, not only what it encloses.

SymbolGallery: a library of thumbnail cells in the collapsible categories
its caller hands it, each category's count beside its header. The cells'
images are painted and cached by SymbolThumbnails.
These pictures are made by tool/screenshots in the repository, with the app's own theme.
The API
package:jet_cad_2d_flutter/jet_cad_2d_flutter.dart is the API. Nothing under
src/ is. package:jet_cad_2d_flutter/export_testing.dart is a test
instrument for this repository's own suites; it is not API and may change in
any release.
While the version is 0.x, a minor release (0.8.0) may break the API, and a
patch release (0.7.3) does not.
The jet-cad packages
| Package | What it is | Depends on |
|---|---|---|
jet_cad_2d_plan |
The plan library: the editor, the widgets and the host API | the kit contract, the renderer and the engine |
jet_cad_2d_kit_architecture |
The architecture kit: walls, openings, rooms, dimensions and furniture | the kit contract, the renderer and the engine |
jet_cad_2d_kit_restaurant |
The restaurant kit: furniture and service units | the kit contract and the engine |
jet_cad_2d_kit |
The kit contract: types, tools and the symbol library format | the renderer and the engine |
jet_cad_2d_flutter |
Flutter rendering and interaction | the engine |
jet_cad_2d |
The pure-Dart engine and document model | nothing of jet-cad |
A host that embeds the planner adds jet_cad_2d_plan and the kits it loads;
the kit contract, the renderer and the engine come with them, and a host
should not also depend on them directly unless it uses their API itself.
Embedding the floor planner in an app is walked through in the host guide.
Support
If jet-cad is useful to you, you can support its development through GitHub Sponsors or Buy Me a Coffee.
License
Apache License 2.0. See LICENSE.
Libraries
- export_testing
- Test instruments for the export (plan 13, P-2): a reader of the PDF
PdfDrawSinkwrites, shared by the render package's tests and the app's. - jet_cad_2d_flutter
- Flutter rendering layer for the
jet_cad_2dengine.