withMaxSize method

Widget withMaxSize({
  1. num? height,
  2. num? width,
})

Creates a new widget that constrains its child to a maximum size.

This can be useful for limiting the size of widgets in a layout.

ElevatedButton(...).withMaxSize(height: 50);

Implementation

Widget withMaxSize({num? height, num? width}) {
  var constraints = const BoxConstraints();

  // don't rely on the default values
  if (height != null) {
    constraints = constraints.copyWith(maxHeight: height.toDouble());
  }
  if (width != null) {
    constraints = constraints.copyWith(maxWidth: width.toDouble());
  }

  return Container(constraints: constraints, child: this);
}