appdimens library
Author & Developer: Jean Bodenberg GIT: https://github.com/bodenberg/appdimens
Library: AppDimens
AppDimens 3.2 — smart and mathematically refined responsive dimensioning for Flutter. Flutter port of the AppDimens Dynamic / KMP family.
Classes
- AppDimensApp
- EN: Wrap your app once:
- AppDimensConfig
- Optional provider-level overrides.
- AppDimensContext
- EN: Platform-neutral window handle. Non-widget APIs take one of these; the Dart port mirrors the Kotlin contract so every calculation is testable without a widget tree.
- AppDimensContextLike
- Structural window view needed by the engine — satisfied by every AppDimensContext and by test fakes; keeps core import cycles flat.
- AppDimensProvider
- EN: InheritedWidget exposing the resolved snapshot to descendants.
- AppDimensReactiveBuilder
-
EN: Rebuilds builder's subtree whenever the published window snapshot
changes — the Flutter analog of a Compose function reading
LocalDimenMetrics.current. Use it around UI whose.sdp/.sspvalues must track live window resizes: - AppDimensScope
-
EN: Global resolution scope — the Flutter analog of the KMP
metricsScope/ ComposeLocalDimenMetrics.AppDimensProviderpublishes each window snapshot here sonum.sdp-style getters resolve through one static read + one multiply (the fast lane). - AppDimensScopeBinder
-
EN: In-tree publisher for
MaterialApp.builder— depends on MediaQuery, so rotation, split-screen, resize and text-scale changes republish the snapshot with zero timers: - AppDimensSnapshot
- Data carried by AppDimensProvider to descendants.
- CacheKey
- Immutable cache key (web-safe: no 64-bit bit packing, exact equality).
- CacheStats
-
Immutable cache statistics (mirrors KMP
CacheStats). - DesignScaleConstants
- Author & Developer: Jean Bodenberg GIT: https://github.com/bodenberg/appdimens
- DimenCache
-
EN: Snapshot-partitioned memoization shared by code APIs, widgets and every
strategy satellite. The dominant families bypass the hash entirely on the
default path because one multiply (~2 ns native) beats a lookup — exactly
like the Kotlin engine (
shouldBypassCache). - DimenCalculationPlumbing
- EN: Inverter resolution, multi-window detection and dp reads. Each strategy module applies its own formula on top of this.
- DimenMetrics
- EN: A value snapshot, not a process-wide mutable "current screen". The constructor contains only the inputs that affect a result; derived factors are calculated once when the snapshot is created. Equality is therefore an exact cache-partition key.
- DimenScaled
-
EN: Immutable builder for conditionally-scaled dimensions. Start from
100.scaledDp(orDimenSdp.scaled(100)), add.screen(...)branches and resolve with the terminal getters. Entries are matched by priority: - DimenScaledEngine
-
EN: Scaled engine. Mirrors the Kotlin
calculateScaledDpexactly: - DimenSdp
-
EN: Static facade mirroring the Kotlin
object DimenSdpcode API — handy for non-extension call sites and for Java-like usage. - DimenSsp
-
EN: Static facade mirroring the Kotlin
object DimenSsp. - DpQualifierEntry
-
Typed qualifier threshold (
type ≥ value). - FakeAppDimensContext
- Fixed context for tests, previews and headless engines.
- MetricsChangeNotifier
- Internal listenable fired by AppDimensScope on each publication.
- ResizeBound
- EN: Bound for a resize range: fixed dp, fixed sp, or a percent of an axis.
- ResizeFixedDp
- Fixed dp bound.
- ResizeFixedSp
- Fixed sp bound.
- ResizeMath
-
EN: Resize math — builds a monotonic step table (max 4096 entries, always
ends at
maxPx) and binary-searches the largest step whose predicate fits. MirrorsResizeMathin Kotlin. - ResizePercent
-
Percent-of-axis bound (
valuein 0…100). - ResizeRangePx
- Precomputed resize range with a fitting resolver.
- ScaledEntry
- One conditional branch inside a builder chain.
- ScaledKernel
- EN: Shared fast-lane kernels — static, zero-allocation (one snapshot read
- ScaledSp
-
EN: Sp variant of DimenScaled — same priority model plus per-branch
fontScalecontrol; started via16.scaledSp. - ScreenConfiguration
- ScreenConfigurationLike
- Screen-configuration subset needed by bounds (avoids widget imports).
- SnapshotCache
- Per-snapshot cache partition with bounded capacity.
- StrategyBranching
-
Shared conditional branching for facilitators (
*Rotate,*Mode,*Qualifier,*Screen) and their logic-only Plain pairs. - StrategyChain
-
EN: Generic conditional chain builder shared by the satellite strategies
(
DimenPercent.scaled(100)…,DimenPower.scaled(100)…). Same four-level priority model as DimenScaled; the winner value is scaled through the strategy formula. - StrategyResolution
-
EN: Shared scope-based resolution used by every satellite stem
(
psdp,pwsdp, …): multi-window guard → formula → unit conversion. Mirrors the Kotlin per-strategycalculate<Strategy>Dpplumbing. - ViewAppDimensContext
- EN: Context built from a FlutterView (no widget tree required). Works on every Flutter platform and updates naturally because callers re-create it per resolution or via AppDimensProvider.
Enums
- AutoResizePercentBasis
- Author & Developer: Jean Bodenberg GIT: https://github.com/bodenberg/appdimens
- CalcType
- Calculation family encoded in a CacheKey.
- DimensOrientation
- Author & Developer: Jean Bodenberg GIT: https://github.com/bodenberg/appdimens
- DpQualifier
- Author & Developer: Jean Bodenberg GIT: https://github.com/bodenberg/appdimens
- DpQualifierLike
- Local axis mirror (keeps this file independent of the common enums).
- Inverter
- Author & Developer: Jean Bodenberg GIT: https://github.com/bodenberg/appdimens
- OrientationRequest
-
Builder-facing orientation request used by DimenScaled-style chains and
facilitators (
*Rotate). - UiModeType
- Author & Developer: Jean Bodenberg GIT: https://github.com/bodenberg/appdimens
- UnitType
- Author & Developer: Jean Bodenberg GIT: https://github.com/bodenberg/appdimens
- ValueType
- Output unit encoded in a CacheKey.
Extensions
- AppDimensContextX on AppDimensContext
- Shared helpers to read the effective axis of a context.
- AppDimensScaledContext on num
-
EN: Explicit-context Scaled resolution. Use when no
AppDimensProvideris available (tests, background isolates, pre-animation code): - AppDimensScaledDp on num
-
EN: The Scaled family on num — resolves through the global
AppDimensScope fast lane published by
AppDimensProvider. - AppDimensScaledFacilitators on num
-
EN: Conditional facilitators for the Scaled family. Each resolves either
this(base) or the branch value through the full engine, honoring the standard flags. The Plain variants are logic-only: they pick between two already-resolved values without scaling anything twice. - AppDimensScaledSp on num
- EN: Scaled sp families on num.
- AppDimensScaledSpFacilitators on num
-
EN: Sp facilitators mirroring the dp set (
sspRotate,sspMode,sspQualifier,sspScreen+ Plain variants). - AppDimensSpContext on num
-
EN: Sp explicit-context variants (
sspOf(context)…).
Constants
- appDimensDescription → const String
- appDimensVersion → const String
Functions
-
buildAppDimensContext(
MediaQueryData? media, FlutterView? view) → ViewAppDimensContext - Builds a ViewAppDimensContext from the ambient MediaQueryData (or a FlutterView fallback), mirroring the KMP window-handle contract.
-
publishAppDimensContext(
AppDimensContext context, AppDimensConfig config) → void - Publishes an explicit context into the global fast-lane scope.
-
resizeFixedDp(
double dp) → ResizeBound - Convenience constructors mirroring the Kotlin helpers.
-
resizeFixedSp(
double sp) → ResizeBound -
resizePercentH(
double percent) → ResizeBound -
resizePercentSw(
double percent) → ResizeBound -
resizePercentW(
double percent) → ResizeBound
Typedefs
- StrategyFormula = double Function(double base, DimenMetrics metrics, DpQualifier effectiveQualifier, bool applyAspectRatio, double? customSensitivityK)
- Pure strategy formula over a resolved axis: receives the base value, the coherent snapshot, the effective (post-inverter) qualifier, the aspect ratio flag and the custom sensitivity.