PositionUnit class abstract

Abstract base class for position units used in element positioning.

PositionUnit defines units that calculate position offsets for elements within a layout container. Unlike size units which determine dimensions, position units specify where elements should be placed along an axis.

Position units can reference various layout properties:

  • Fixed pixel offsets
  • Viewport and content dimensions
  • Scroll positions and overflow amounts
  • Child element sizes
  • Cross-axis positions

Position units support mathematical operations and can be combined to create complex positioning expressions similar to CSS calc().

Common uses include:

  • Absolute positioning of elements
  • Sticky positioning relative to scroll
  • Centering based on element or viewport size
  • Scroll-aware animations

Example:

// Center an element: 50% viewport - 50% child size
final centered = PositionUnit.viewportSize * 0.5 - PositionUnit.childSize() * 0.5;

// Position 20px from viewport end
final offset = PositionUnit.viewportSize - PositionUnit.fixed(20);
Implementers
Available extensions

Constructors

PositionUnit()
Creates a const position unit.
const
PositionUnit.calc(PositionUnit a, PositionUnit b, CalculationOperation operation)
Creates a calculated position unit combining two position units with an operation.
const
factory
PositionUnit.childSize([Object? key])
Creates a position unit based on a child element's size.
const
factory
PositionUnit.constrained({required PositionUnit position, PositionUnit min, PositionUnit max})
Creates a constrained position unit that clamps values between min and max.
const
factory
PositionUnit.cross(PositionUnit position)
Creates a position unit that uses the cross-axis value of another position unit.
const
factory
PositionUnit.fixed(double value)
Creates a fixed position unit with the specified pixel value.
const
factory
PositionUnit.relative(double factor)
Creates a position unit relative to parent element's size.
const
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clamp({PositionUnit min = const PositionFixed(double.negativeInfinity), PositionUnit max = const PositionFixed(double.infinity)}) PositionUnit

Available on PositionUnit, provided by the PositionUnitExtension extension

Constrains this position unit within the specified min and max bounds.
computePosition({required ParentLayout parent, required ChildLayout child, required LayoutAxis direction}) double
Computes the actual position value for this unit.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
times(double other) PositionUnit

Available on PositionUnit, provided by the PositionUnitExtension extension

Multiplies a position unit by a scalar.
toCodeString() String
Converts the position unit to a code string representation.
toString() String
A string representation of this object.
inherited

Operators

operator *(Object other) PositionUnit

Available on PositionUnit, provided by the PositionUnitExtension extension

Multiplies two position units.
operator +(PositionUnit other) PositionUnit

Available on PositionUnit, provided by the PositionUnitExtension extension

Adds two position units together.
operator -(PositionUnit other) PositionUnit

Available on PositionUnit, provided by the PositionUnitExtension extension

Subtracts one position unit from another.
operator /(PositionUnit other) PositionUnit

Available on PositionUnit, provided by the PositionUnitExtension extension

Divides one position unit by another.
operator ==(Object other) bool
The equality operator.
inherited
operator unary-() PositionUnit

Available on PositionUnit, provided by the PositionUnitExtension extension

Negates this position unit (equivalent to 0 - this).

Static Methods

lerp(PositionUnit a, PositionUnit b, double t) PositionUnit
Linearly interpolates between two position units.

Constants

boxOffset → const PositionUnit
A position unit representing the scroll offset (also called boxOffset).
contentOverflow → const PositionUnit
A position unit representing the amount content overflows the viewport.
contentSize → const PositionUnit
A position unit representing the total content size along the axis.
contentUnderflow → const PositionUnit
A position unit representing the amount content underflows the viewport.
scrollOffset → const PositionUnit
A position unit representing the current scroll offset.
viewportEndBound → const PositionUnit
A position unit representing where the viewport ends in content coordinates.
viewportSize → const PositionUnit
A position unit representing the full viewport size along the axis.
viewportStartBound → const PositionUnit
A position unit representing where the viewport starts in content coordinates.
zero → const PositionUnit
A position unit with value zero.