Home > Blockchain >  Flutter: MediaQuery.of(context).size is not match emulator screen size
Flutter: MediaQuery.of(context).size is not match emulator screen size

Time:10-11

I am using flutter 3.3.2 on Android SDK v31.0.0

I created an emulator with screen size 6.1 inch - 393 x 852, but the screen size return from MediaQuery is different as below:

  • MediaQuery.of(context).size.width= 394
  • MediaQuery.of(context).size.height = 804
  • MediaQuery.of(context).size.devicePixelRatio = 1

Could anyone help me to explain why it is different ? Or did i miss something ?

CodePudding user response:

use MediaQuery like this method it will take auto screen size.

write inside BuildContext.

Widget build(BuildContext context) {

//write here

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

return new Container( height :height, width : width, color :Colors.red, );

CodePudding user response:

Finally i figured out the reason. The difference is because out the system navigation bar at the bottom screen. I disable it by setting the hw.mainKeys=yes. Then the size is returned by MediaQuery is equal to emulator screen size.

  • Related