layout method

  1. @override
void layout(
  1. Context context,
  2. BoxConstraints constraints, {
  3. bool parentUsesSize = false,
})
override

First widget pass to calculate the children layout and bounding box

Implementation

@override
void layout(Context context, BoxConstraints constraints,
    {bool parentUsesSize = false}) {
  final shrinkWrapWidth =
      widthFactor != null || constraints.maxWidth == double.infinity;
  final shrinkWrapHeight =
      heightFactor != null || constraints.maxHeight == double.infinity;

  if (child != null) {
    child!.layout(context, constraints.loosen(), parentUsesSize: true);
    assert(child!.box != null);

    box = constraints.constrainRect(
        width: shrinkWrapWidth
            ? child!.box!.width * (widthFactor ?? 1.0)
            : double.infinity,
        height: shrinkWrapHeight
            ? child!.box!.height * (heightFactor ?? 1.0)
            : double.infinity);
    final resolvedAlignment = alignment.resolve(Directionality.of(context));
    child!.box = resolvedAlignment.inscribe(child!.box!.size, box!);
  } else {
    box = constraints.constrainRect(
        width: shrinkWrapWidth ? 0.0 : double.infinity,
        height: shrinkWrapHeight ? 0.0 : double.infinity);
  }
}