Published
zpl_kit (pub.dev Package)
Overview
About the Project
A declarative layout engine for generating Zebra Programming Language (ZPL) strings with Flexbox-like components. A three-pass engine resolves ^FO field origins from parent constraints, so labels are composed as widget trees instead of concatenated strings and hand-calculated coordinates. Ships batch label building, offline and Labelary-backed preview tooling, and TCP or HTTP printer connectors.
How it works
Engineering Flow
Constraints down
Each parent passes ZplConstraints carrying the maximum available width and height down to its children, following the same layout protocol shape as Flutter.
Sizes up
Children measure themselves against those constraints and report their resolved size back up to the parent.
Compilation
With every size locked, a final pass walks the tree and emits the ZPL string, injecting the calculated ^FO field origin coordinates as it goes.
Preview or print
ZplKit.build renders a label at a chosen ZplLabelSize, while ZplPreview and ZplLabelaryPreview verify the output and TcpZplPrinter or HttpZplPrinter send it to hardware.
Problems solved
Challenges & Resolution
- Challenge
- Hand-written ZPL means string concatenation plus absolute ^FO coordinate math, so moving one element forces recalculating every coordinate below it.
- Resolution
- Built a three-pass layout engine that derives positions from parent constraints, exposed through ZplColumn, ZplRow, ZplExpanded, ZplSpacer, ZplCenter, ZplStack, and ZplPadding with ZplEdgeInsets.
- Benefit
- Labels are composed coordinate-free and nest freely, such as a ZplRow inside a ZplExpanded child of a ZplColumn, with no manual coordinate rework.
- Challenge
- Checking whether a label actually lays out correctly normally means sending it to a physical printer, which slows the edit-and-check loop.
- Resolution
- Added ZplPreview for instant offline rendering during development and ZplLabelaryPreview for true-to-printer verification through the Labelary API, with rendering based on ISO-standard math for barcode scaling and text constraints.
- Benefit
- Layout can be inspected without hardware in the loop, keeping verification close to where the label is written.
- Challenge
- Real print jobs are rarely one label on one transport: multiple copies, multi-label runs, and local-network versus web-based printing all need to be served.
- Resolution
- Mapped printQuantity onto ^PQ, added ZplKit.buildBatch to concatenate many labels into a single ZPL stream for one network request, and shipped TcpZplPrinter for direct local-network printing alongside HttpZplPrinter for web apps and REST bridges, with ZplPrinterConnector left open for subclassing.
- Benefit
- The same label tree targets mobile, desktop, and web, and new transports such as Bluetooth or USB can be added without touching layout code.
Result
Outcome
The WMS Mobile work already printed by sending pure ZPL over a TCP socket, and zpl_kit generalises that production need into a reusable, MIT-licensed package on pub.dev. Instead of concatenating strings and tracking field origins by hand, labels are declared as widget trees and compiled by the layout engine, with the output verified on industrial hardware including the Zebra GK420T for 4x6 shipping labels and the Zebra ZD series for general ZPLII compatibility.
Highlights
Key Highlights
- A declarative layout engine for generating Zebra Programming Language (ZPL) strings with Flexbox-like components.
- Provides coordinate-free design using ZplColumn, ZplRow, and ZplPadding to transform component trees into raw ZPL strings.
- Includes widgets like ZplText and ZplBarcode, complete with comprehensive DartDoc coverage and published natively on pub.dev.