size method
Applies tight size constraints to this widget.
Implementation
@widgetFactory
Widget size({
double? width,
double? height,
Size? size,
double? square,
bool? expand,
bool? shrink,
bool fractional = false,
bool overflow = false,
AlignmentGeometry? alignment,
}) {
assert(
!fractional || (expand == null && shrink == null),
'fractional cannot be used with expand or shrink',
);
assert(
!overflow || (expand == null && shrink == null),
'overflow cannot be used with expand or shrink',
);
assert(
overflow || alignment == null,
'alignment can only be used with overflow',
);
assert(() {
_debugCheckParameterCombinations(modifier: 'size', [
{'width': width, 'height': height},
{'size': size},
{'square': square},
{'expand': expand},
{'shrink': shrink}
]);
return true;
}());
if (expand ?? false) {
return FleetSizedBox.expand(child: this);
} else if (shrink ?? false) {
return FleetSizedBox.shrink(child: this);
} else {
width ??= size?.width ?? square;
height ??= size?.height ?? square;
if (fractional) {
return FleetFractionallySizedBox(
widthFactor: width,
heightFactor: height,
child: this,
);
} else if (overflow) {
return FleetSizedOverflowBox(
size: Size(width!, height!),
alignment: alignment ?? Alignment.center,
child: this,
);
} else {
return FleetSizedBox(
width: width,
height: height,
child: this,
);
}
}
}