computePosition method

  1. @override
double computePosition({
  1. required ParentLayout parent,
  2. required ChildLayout child,
  3. required LayoutAxis direction,
})
override

Computes the actual position value for this unit.

Position units are computed after inset, size, and spacing have been resolved, allowing them to reference final layout values.

Parameters:

  • parent: The parent layout context
  • child: The child element being positioned
  • direction: The layout direction (main or cross axis)

Returns the computed position offset.

Implementation

@override
double computePosition({
  required ParentLayout parent,
  required ChildLayout child,
  required LayoutAxis direction,
}) {
  if (key == null) {
    return switch (direction) {
      LayoutAxis.horizontal => child.size.width,
      LayoutAxis.vertical => child.size.height,
    };
  }
  ChildLayout? otherChild = parent.findChildByKey(key!);
  if (otherChild == null) {
    return 0.0;
  }
  return switch (direction) {
    LayoutAxis.horizontal => otherChild.size.width,
    LayoutAxis.vertical => otherChild.size.height,
  };
}