screenWidth property
double
get
screenWidth
Get the logical screen width multiplied by this number.
Initialization requirements:
- Recommended: call
FlutterSExtensions.update(context)in yourMaterialApp.builderto keep values fresh across hot reloads. - Lazy init: if no explicit init has occurred, a first view is used
from
WidgetsBinding.instance.platformDispatcher.views. This throws when no view is available (e.g., very early or certain tests).
Usage example in layout:
// In a news app header: take 90% of screen width
SizedBox(width: 0.9.screenWidth);
Error handling:
- Throws
StateErrorif the extension cannot be initialized (no binding or no available view). Ensure the app is running and initialized.
Value of this should be between 0 and 1.
Implementation
double get screenWidth {
final mq = FlutterSExtensions.mediaQuery();
return this * mq.size.width;
}