setWidth method
setWidth
uses its argument width
to calculate the initial widget width
in pixels and from that the package can deal with all the calculation.
setWidth
{@tool sample}
Container(
width: response.setWidth(300),
height: response.setHeight(200),
color: Colors.teal,
), //Container
{@end-tool}
width
is the widget width which you want it to be the same across any screen size.
Implementation
///`width` is the widget width which you want it to be the same across any screen size.
double setWidth(double width) {
if (_fixedWidthFactor == null || _blockWidth == null || _fixedWidthFactor == null || _originalWidth == null)
throw DidNotCallInit();
double _widthCorrectionFactor = _fixedWidthFactor!;
//if the current device is Mobile
if (_fixedWidthFactor! < _blockWidth! * 0.6) {
_widthCorrectionFactor *= 1.48;
}
//if the original device is Tablet
if (_originalWidth! > _screenWidth!) {
_widthCorrectionFactor /= 1.75;
}
return ((width / _widthCorrectionFactor) * _blockWidth!);
}