constrained method

Widget constrained({
  1. Key? key,
  2. BoxConstraints? boxConstraints,
  3. double? minWidth,
  4. double? maxWidth,
  5. double? minHeight,
  6. double? maxHeight,
})

Imposes additional constraints on its child.

Only boxConstraints or minWidth, maxWidth, minHeight, and maxHeight can be provided. Providing both a constraint and min/max values will throw an assertion error.

Implementation

Widget constrained({
  Key? key,
  BoxConstraints? boxConstraints,
  double? minWidth,
  double? maxWidth,
  double? minHeight,
  double? maxHeight,
}) {
  assert(
    boxConstraints == null ||
        (minWidth == null &&
            maxWidth == null &&
            minHeight == null &&
            maxHeight == null),
    'Cannot provide both a constraint and min/max values.',
  );
  return ConstrainedBox(
    key: key,
    constraints: boxConstraints ??
        BoxConstraints(
          minWidth: minWidth ?? 0,
          maxWidth: maxWidth ?? double.infinity,
          minHeight: minHeight ?? 0,
          maxHeight: maxHeight ?? double.infinity,
        ),
    child: this,
  );
}