xxxxxxxxxx
@override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return Container();
}
xxxxxxxxxx
double height = MediaQuery.of(context).size.height;
double width = MediaQuery.of(context).size.width;
xxxxxxxxxx
MediaQuery.of(context).size.width //for width
MediaQuery.of(context).size.height //for height
xxxxxxxxxx
// 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).viewPadding;
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;
xxxxxxxxxx
import 'package:flutter/material.dart';
class ScreenWidthWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
double screenWidth = MediaQuery.of(context).size.width;
return Text('Screen Width: $screenWidth');
}
}
xxxxxxxxxx
// All height of screen
double screenHeight = MediaQuery.of(context).size.height
// height of screen only
double screenHeight = MediaQuery.of(context).size.height -
MediaQuery.of(context).padding.top -
kToolbarHeight -
kBottomNavigationBarHeight;
xxxxxxxxxx
MediaQuery.of(context).size.height - // total height
kToolbarHeight - // top AppBar height
MediaQuery.of(context).padding.top - // top padding
kBottomNavigationBarHeight // BottomNavigationBar height
xxxxxxxxxx
//In logical pixels
var width = MediaQuery.of(context).size.width;
var height = MediaQuery.of(context).size.height;
var padding = MediaQuery.of(context).padding;
var safeHeight = height - padding.top - padding.bottom;
xxxxxxxxxx
dependencies:
flutter:
sdk: flutter
# add flutter_ScreenUtil
flutter_screenutil: ^0.4.2