layer_canvas_flutter 0.1.0
layer_canvas_flutter: ^0.1.0 copied to clipboard
Flutter widgets and adapters for the layer_canvas 2D compositor.
0.1.0 #
Targets layer_canvas: ^0.1.0 (was ^0.1.0-beta.4) and surfaces everything the
core gained since — still with only Flutter types.
- Stroke cap/join/miter/dash —
Layers.rectangle/Layers.pathgainstrokeCap/strokeJoin/strokeMiterLimit, usingdart:ui's ownStrokeCap/StrokeJoin;Layers.pathadditionally acceptsdashArray/dashOffset(scaled bypixelRatiolike every other length), since dashing only applies to aPathLayer's stroke in the core. clipBehavior—Layers.rectangle/text/image/pathaccept aClip clipBehavior(any value butClip.noneclips the layer to itssize), mapping to the core'sLayer.clipToBounds. Not onLayers.group/Layers.svg: the core expands aGroupinto its concrete descendants before rendering, leaving no single surface to clip.scale/alignment— everyLayersfactory now acceptsscale(uniform, via the core'sLayerTransform.scale) andalignment(via the existingAlignmentGeometryX.toFractionalPoint2D(), sorotation/scalecan pivot around a corner instead of the center), alongsideposition/rotation.- Word-wrap —
Layers.textword-wraps into asizewith a width set (greedily, only at spaces), vertically centered withinsize's height — no new parameter, this was already reachable, just newly documented. - Exact
FontWeightmapping —FontWeightX.toTextWeight()now uses the core'sTextWeight.fromValue(added inlayer_canvas0.1.0-beta.6) for an exact 1:1 conversion, instead of snapping to the nearest of 7 named constants. AssetImageSource— aLayerImageSourcethat lazily loads a Flutter asset by key (optionally from apackage) instead of eagerly reading bytes likeImageSources.asset, so it's cheap to build ahead of time and compact to serialize (a short string instead of a base64 blob). Every widget in this package (and the newScenes.encode/saveToFile) resolves it against the ambientAssetBundlebefore rendering; registers its ownLayerRegistrydecoder automatically, soScene.fromJsonreconstructs it too.- Scene persistence —
Scene.toJson()/Scene.fromJson()(added inlayer_canvas0.1.0-beta.6) work as-is through this package's re-exportedScene; only documented here, no new API. - Export —
Scenes.encode(scene, {format})andScenes.saveToFile(scene, path, {format})rasterize aScenetopng/bmp/qoibytes or a file (via the re-exportedOutputFormat), resolving anyAssetImageSourcefirst — for exporting a scene instead of displaying it, which every widget still does as PNG. - Re-exports
OutputFormatandLayerRegistry(+ itsLayerFromJson/ImageSourceFromJsontypedefs) alongside the previously re-exported core types. - Rendering never blocks the UI isolate —
LayerCanvas,SceneWidget,SvgLayer, andScenes.encode/saveToFilenow run the native render call on a background isolate internally (renderOffMainIsolate), instead of on the calling isolate. The corelayer_canvaspackage's ownRenderer.renderstays synchronous-under-the-hood on purpose — it's plain Dart with no UI thread to protect, so a CLI/batch consumer isn't charged isolate-spawn overhead for a benefit only a Flutter app needs; this package is where that trade makes sense, so it's where the offload lives.
0.1.0-beta.1 #
Initial release.
Layers: static factories (rectangle,text,image,path,svg,group) that buildlayer_canvaslayers from Flutter types (Color,Offset,Size,FontWeight,TextAlign,BoxFit,Gradient,PathFillType) instead of the core'sColor32/Point2D/TextWeight/FillRule. Every factory takes an optionalpixelRatioso layers built in logical units land at physical-pixel resolution without scaling each measurement by hand.Layers.rectangle/Layers.pathaccept agradient:— a FlutterLinearGradient,RadialGradient, orSweepGradient— converted via the newGradientX.toLayerGradient()to the core'sLinearGradient/RadialGradient/ConicGradient(added inlayer_canvas0.1.0-beta.3).LayerPathBuilder: builds aPathLayer's vector geometry with the same method names and shapes asdart:ui's ownPath(moveTo,lineTo,quadraticBezierTo,cubicTo,arcToPoint,close, plus.polygon/.polyline/.circle/.ovalfactories), so drawing aLayers.pathshape reads the same as drawing one in aCustomPainter.Layers.svg: places an already-SvgDocument.parsed document as a group, with the sameposition/size/pixelRatioshape as every otherLayersfactory.SvgLayer: a widget that displays anSvgDocumentat a givenwidth/heightwith a realBoxFit(via Flutter's ownFittedBox—layer_canvashas no native crop/cover for a vector group). Not namedSvgPictureon purpose: that'spackage:flutter_svg's widget, and the two render through entirely different paths.LayerCanvas.onLayerTap: reports the topmostLayerunder a tap, via the core's newhitTestScene(layer_canvas0.1.0-beta.4). Coordinates are mapped throughfit(viaapplyBoxFit), so this is correct whether the widget's box matches the scene's own aspect ratio or not. A bounding-box test against each layer'ssize(not its exact painted shape), and a layer with no explicitsizenever matches — seehitTestScene's own doc comment for the precise contract.Scenes.of: builds aScenefrom achildrenlist instead of the core's mutate-after-constructionScene(...)..add(...)..add(...).LayerCanvas: a widget that renders aScene— fixed, or built viasceneBuilder(logicalSize, pixelRatio)— scaled for the device pixel ratio, with the renderFuturecached by scene identity/size/pixel ratio/rebuildKey, andplaceholderBuilder/errorBuilderhooks.SceneWidget: a thin wrapper overScenes.of+LayerCanvasshaped like a Flutter layout widget (SceneWidget(width:, height:, children: [...]), similar toStack) for fixed-size scenes that don't need per-build DPR scaling. Rebuilds itsSceneon everybuild()— no render caching across rebuilds, unlike aLayerCanvasgiven a stablescene:.LayerCanvasFonts: loads fonts declared in the app'spubspec.yamlinto the nativeFontRegistryat startup (ensureInitialized), optionally scoped to afamiliesallow-list, so an app can turn offlayer_canvas's embedded default font (hooks.user_defines.layer_canvas.embed_default_font: false) and preload its own font instead. Now registers every declared weight of a family (viaFontRegistry'sweight:param from 0.1.0-beta.3), not just its first face — italic faces are skipped, sinceFontRegistryhas no italic/upright concept to register them under.- Adapters (
ColorX,OffsetX/SizeX,FontWeightX/TextAlignX,BoxFitX,PathFillTypeX,GradientX/TileModeX/AlignmentGeometryX,ImageSources) converting between Flutter andlayer_canvascore types, exported for advanced/manual use. - Requires
layer_canvas: ^0.1.0-beta.4(was^0.1.0-beta.2).