frameConstrained method

Widget frameConstrained(
  1. {required double maxWidth,
  2. required double minHeight,
  3. required double minWidth,
  4. required double maxHeight,
  5. double? idealHeight,
  6. Alignment? alignment,
  7. double? idealWidth}
)

A similar extension to frame, but that uses BoxConstraints instead of hardcoded size values.

Implementation

Widget frameConstrained({
  required double maxWidth,
  required double minHeight,
  required double minWidth,
  required double maxHeight,
  double? idealHeight,
  Alignment? alignment,
  double? idealWidth,
}) {
  Widget content = this;
  if (alignment != null) {
    content = Align(
      alignment: alignment,
      child: this,
    );
  }
  final ConstrainedBox box = ConstrainedBox(
    constraints: BoxConstraints(
      minWidth: minWidth,
      maxWidth: maxWidth,
      minHeight: minHeight,
      maxHeight: maxHeight,
    ),
    child: content,
  );

  if (idealWidth != null || idealHeight != null) {
    return SizedBox(
      width: idealWidth,
      height: idealHeight,
      child: box,
    );
  }

  return box;
}