skip to Main Content

I use final screenHeight = MediaQuery.of(context).size.height; and final screenWidth = MediaQuery.of(context).size.width; for my width and height of Widgets such as SizedBox and Container.

When I use one device to make the sizes, for example screenHeight*0.1 it fits well. But when I bring in a different device it gives me an overflow. I have to keep adjusting the coefficient until both fit perfectly.

What can I do so that when I make the sizes, it fits well with all device. Because, let’s face it, I don’t know which device my user will be using.

I tried it on both physical and virtual devices

2

Answers


  1. I think you are facing problem to show some sized Box or container according to height and width of device. So you can use Expanded widget. You can wrap widget with Expanded so that it can occupy required space.
    If you provide you code so I can understand better.

    Login or Signup to reply.
  2. You should use MediaQuery to define the size that the widgets must occupy in the screen. If you have widgets that must fit that size, you can use the FittedBox widget, that makes its content to fit its parent.

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