smart_measurer 0.1.4
smart_measurer: ^0.1.4 copied to clipboard
Measure a widget's real size and react to it, with frame-accurate precision tracking and a zero-delay, size-aware decoration painter for pure-drawing use cases.
Changelog #
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
0.1.4 - 2026-08-11 #
Added #
shrinkToFitonSmartMeasurer/SimpleMeasurer— whenconstrainToAvailableSpaceis true and content does not fit the available space on the non-scrollable axis, settingshrinkToFitto true scales the content down to fit (likeBoxFit.scaleDown) instead of clipping it. Defaults to false (clipping).
Changed #
constrainToAvailableSpacewithout scrolling now actually prevents visual overflow. Previously it only applied aConstrainedBoxwith the same max constraints, which is a no‑op on Flex children that overflow their own bounds. Now aClipRect(and optionallyFittedBoxviashrinkToFit) ensures the content is visually clipped or shrunk to the available space, matching the flag’s contract.
0.1.3 - 2026-08-11 #
Added #
-
sizeChangeThresholdonSmartMeasurer/SimpleMeasurer— ignores measurement deltas smaller than a given number of logical pixels, to absorb sub-pixel jitter coming from an animating parent layout instead of rebuilding on every one. When a change is filtered out but the generation/constraints did change, the previous size is kept rather than snapping to the near-identical new one, to avoid visible jitter. -
onSizeChangedonSmartMeasurer/SimpleMeasurer— a side-effect callback fired on every committed precise measurement, independently ofbuilder, for cases (analytics, syncing a scroll offset, driving an external animation) that shouldn't require rebuilding the wholebuildersubtree. -
notifyDebounceonSmartMeasurer/SimpleMeasurer— debounces rapid successive measurements (screen rotation, keyboard animation) into a single update instead of one per frame. -
animationDuration/animationCurveonSmartMeasurer/SimpleMeasurer— animates the displayed precise size smoothly instead of snapping to it immediately, for a "grow/shrink" transition. Has no effect on estimated sizes. -
SmartMeasurerController— an externalChangeNotifierexposingsize,isPrecise, andconstraints, so code outside ofbuildercan read the current measurement. Pass it via the newcontrollerparameter onSmartMeasurer/SimpleMeasurer. Notifications are deferred to a post-frame callback, so it's always safe to callsetStatefrom a listener. -
estimateStrategy(SmartMeasurerEstimateStrategy:zero,previousSize,constraints,custom) onSmartMeasurer/SimpleMeasurer— an explicit, extensible replacement foruseConstraintsAsInitialEstimate, which is now deprecated but still honored whenestimateStrategyis left unset. -
ignorePointerDuringEstimateonSmartMeasurer/SimpleMeasurer— wraps the result inIgnorePointerwhileisPreciseisfalse, so taps never land on a provisional layout. -
onDebugWarningonSmartMeasurer/SimpleMeasurer— redirects the package's internal warnings (invalid estimate, missingmeasuredChild, etc.) to a custom sink instead ofdebugPrint, so production apps can route them into their own logging pipeline. -
placeholderBuilderonSmartMeasurer/SimpleMeasurer— a widget shown instead ofbuilder's output until the very first precise measurement is ever obtained (e.g. a skeleton). The real child keeps measuring offstage in the background so the switch-over happens as soon as layout is ready. -
debugPaintEstimatedSizeonSmartMeasurer/SimpleMeasurer— debug-only red/green border around the result depending onisPrecise, to spot flicker or measurement issues visually. Compiled out entirely outside of debug builds. -
unconstrainedonSmartMeasurer— auto-wrapsmeasuredChildin anUnconstrainedBox, the same trickSimpleMeasureralready used internally, so it always reports its natural size. -
constrainToAvailableSpace,scrollable,scrollDirectiononSmartMeasurer/SimpleMeasurer— optional built-in handling for content that might exceed the available space, instead of requiring users to combineLayoutBuilder+ConstrainedBox/SingleChildScrollViewby hand around every measurer. -
SmartMeasurerGroup— a new, lighter widget that measures a list of children at once and hands back their sizes (List<Size>) plus anallPreciseflag, for layout decisions that depend on several sizes at once (e.g. equalizing a row of chips) without nesting multipleSmartMeasurers. -
MeasuredDecoration.onSizeChanged— an optional callback fired after layout whenever the child's size changes, independent ofpainterand without forcing an extra paint. Deferred to the end of the frame, so it's always safe to callsetStatefrom it.
Changed #
- Breaking:
MeasuredDecoration.paintersignature.painternow receives the child'sBoxConstraintsin addition toCanvasandSize:void Function(Canvas canvas, Size size, BoxConstraints constraints). Existing painters need one extra parameter added to their signature; no other change is required. See the README's "Migrating from 0.1.x" section.
Deprecated #
useConstraintsAsInitialEstimateonSmartMeasurer/SimpleMeasurer— superseded byestimateStrategy(SmartMeasurerEstimateStrategy.constraints). Still fully functional as a fallback whenestimateStrategyis left unset; no removal planned in the near term.
Notes #
- Aside from the
MeasuredDecoration.paintersignature change, every addition in this release is optional and additive — existing code usingSmartMeasurer,SimpleMeasurer, orSmartMeasurerController-less setups keeps working unchanged.
0.1.2 - 2026-08-11 #
Added #
-
debugLabelonSmartMeasurer(optional, propagated bySimpleMeasurer).
Provides a human-readable name for the widget, visible in debug error messages (duplicate key exceptions) and in the widget inspector, helping to distinguish multiple nestedSmartMeasurerinstances. -
debugFillPropertiesonRenderMeasuredDecorationso the inspector now showspainteridentity andpaintBehindChildvalue, matching what_RenderMeasuredChildalready exposes for the measurement infrastructure.
Changed #
-
Simplified
_isValidForConstraints– the manual ternary check was redundant becauseBoxConstraints.maxWidth/maxHeightalready returndouble.infinitywhen the axis is unbounded. Replaced by a direct call toconstraints.isSatisfiedBy(size), which is the canonical method and also slightly more efficient. -
Renamed shadowed parameter in
_scheduleNotificationfromconstraintstousedConstraints, avoiding a name conflict with the inheritedRenderBox.constraintsgetter. No behaviour change. -
Frame‑detection in the debug “no precise measurement” warning re‑implemented with a
postFrameCallback‑based flag instead ofSchedulerBinding.currentFrameTimeStamp. This avoids a potential assertion error if_checkMissingChildis called outside an active frame, and matches the pattern already used elsewhere in the file. Debug‑only, no release impact.
Notes #
- All changes are internal to the implementation; the public API is fully
backward‑compatible with
0.1.1. ThedebugLabelparameter is an optional addition and does not affect existing code.
0.1.1 - 2026-08-11 #
Fixed #
-
SimpleMeasurerreported a fake, self-referential size instead of the child's real size. The child was overlaid withPositioned.fill, which forces tight constraints on it (min == max, derived from the decorationbuilderhad just returned). Since aRenderBoxunder tight constraints must report exactly those constraints back, the "measured" size was really just an echo of the previous size plus whatever offset the decoration added — never the child's actual natural size. This broke the primary use case shown in the README (a decoration that sizes itself to a piece of text).measuredChildis now wrapped inUnconstrainedBoxinstead, guaranteeing it is always laid out with no constraints and always reports its true natural size, regardless of whatbuilderreturns or what constraints are imposed onSimpleMeasurerby its own parent. -
MeasuredDecorationcould keep painting a stale decoration.painterandpaintBehindChildwere plain field assignments inupdateRenderObject, so replacingpainterwith a new closure (e.g. one capturing a different color) did not trigger a repaint — the previous frame's drawing stayed on screen until something else happened to repaint the render object.painterandpaintBehindChildare now real setters that compare the old and new value and callmarkNeedsPaint()when they actually change.
Changed #
-
SimpleMeasurergained analignmentparameter (AlignmentGeometry, defaultAlignment.center), controlling where the child is positioned within the decoration now that it's no longer force-fit withPositioned.fill. This restores (and makes explicit) the centered overlay behavior implied by the original README example. -
The "no precise measurement after 3 frames" debug warning in
SmartMeasurernow counts real frames, not builds. Previously the internal counter incremented on every call tobuild(), so a parent that rebuilds more than once per frame could trigger the warning long before three actual frames had passed. It's now debounced with aSchedulerBinding.addPostFrameCallback-based flag, so it only advances once per frame regardless of how many timesbuild()runs within it. Debug-mode only; no effect on release builds.
Notes #
- No public API was removed or had its meaning changed —
SimpleMeasurergained one new optional named parameter (alignment), everything else is source- and behavior-compatible for correctly-functioning code. Any code that was implicitly relying onSimpleMeasurer's old (incorrect) tautological sizing behavior will now see accurate sizes instead — if your decoration looked fine before, it will look at least as good now; if it looked subtly "stuck" or unresponsive to content changes, this is why, and it's now fixed.
0.1.0 Initial release #
- Initial release of
smart_measurer:SmartMeasurer,SimpleMeasurer, andMeasuredDecoration.