skip to Main Content

is there anyone facing the same issue in flutter 3.10.1, Dart 3.0.1?
The

MediaQuery.of(context).size.width 

and

MediaQuery.of(context).size.height 

are always 0.

MediaQuery.of(context).size.width 

and

MediaQuery.of(context).size.height 

had worked with no issue in previous Flutter 2.19, but i get this issue after upgrade.

2

Answers


  1. I am calling it like

      @override
      Widget build(BuildContext context) {
       
        Size screenSize = MediaQuery.of(context).size;
        dev.log('Width:  ${screenSize.width}');
        dev.log('Heigth:  ${screenSize.height}');
    ....}
    

    And this is working flawless for me! I have always the newest stable update.

    I also tried to call it in a really small Container, also then I still get the full size of the screen.

    • since you updated, there are some other parts not working fine, so you size measurement doesnt fire correctly
    • You have to clean your project like: 1) flutter clean, 2) flutter pub get 3) close and reopen your editor. (If you want repeat 1 and 2).
    • You calling it wrong?

    (Less Likely):

    • you are using a real device and it is blocking it some how?
    • your emulator is blocking it or its "broken"?
    Login or Signup to reply.
  2. I use Getx and Sizer wrappig over MaterialApp (). Yes that happens with me too. Not only that, your runApp() and sometimes even void main() also gets run multiple times. I think that problem is from flutter side. But if in your case only runApp() gets run multiple times then, currently I solved it by …

    if(MediaQuery.of(context).size.width > 0) return MaterialApp();
    return const SizedBox();
    

    you need to use builder or StatelessWidget for context. If you find any better solution from project setting, please share them.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search