flutter get width of screen code example

Example 1: flutter get width of screen

double height = MediaQuery.of(context).size.height;
double width = MediaQuery.of(context).size.width;

Example 2: flutter screen size

double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;

Example 3: get the available screen height flutter

Getting width is easy but height can be tricky, following are the ways to deal
with height

// Full screen width and height
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;

// Height (without SafeArea)
var padding = MediaQuery.of(context).padding;
double height1 = height - padding.top - padding.bottom;

// Height (without status bar)
double height2 = height - padding.top;

// Height (without status and toolbar)
double height3 = height - padding.top - kToolbarHeight;

Example 4: how to get the display size of mobile display in flutter

getHeightWidth(context){
 
    double width = MediaQuery.of(context).size.width;
 
    double height = MediaQuery.of(context).size.height;
 
    setState(() {
     heightHolder = height.roundToDouble();
     widthHolder = width.roundToDouble() ; 
    });
 
  }

Example 5: how to give width based on screen size flutter

dependencies:
  flutter:
    sdk: flutter
  # add flutter_ScreenUtil
  flutter_screenutil: ^0.4.2

Tags:

Misc Example