constrainedWidth function
double
constrainedWidth(
- BuildContext context,
- double preferredWidth, {
- double? constraintWidth,
- bool? shouldConstraint,
Method to get preferredWidth constrained, if is bigger than media query width, will return constraintWidth if not null, else return media query.
Implementation
double constrainedWidth (BuildContext context, double preferredWidth, {double? constraintWidth, bool? shouldConstraint}) {
double width = preferredWidth;
double def = constraintWidth ?? MediaQuery.of(context).size.width;
bool constraint = shouldConstraint ?? preferredWidth > def;
if (constraint) {
width = def;
}
return width;
}