프로그래밍/Flutter

[Flutter] Screen, StatusBar Size

YuminK 2022. 4. 27. 09:06

UI 개발 중에 위치를 Padding 처리를 직접하고 싶을 때 사용하기에 좋다.

double getScreenWidth(BuildContext context) => MediaQuery.of(context).size.width;
double getScreenHeight(BuildContext context) => MediaQuery.of(context).size.height;
double getStatusBarSize(BuildContext context) => MediaQuery.of(context).padding.top;
double getPixelRatio(BuildContext context) => MediaQuery.of(context).devicePixelRatio;

/*
// 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;
 */