Flutter screen size

Tom O'Sullivan picture Tom O'Sullivan · Mar 29, 2018 · Viewed 99.3k times · Source

I've created a new application on flutter, and I've had problems with the screen sizes when switching between different devices.

I created the application using the Pixel 2XL screen size, and because I've had containers with child of ListView it's asked me to include a height and width for the container.

So when i switch the device to a new device the container is too long and throws an error.

How can i go about making it so the application is optimised for all screens?

Answer

yashthakkar1173 picture yashthakkar1173 · Sep 13, 2018

You can use:

  • double width = MediaQuery.of(context).size.width;
  • double height = MediaQuery.of(context).size.height;

To get height just of SafeArea (for iOS 11 and above):

  • var padding = MediaQuery.of(context).padding;
  • double newheight = height - padding.top - padding.bottom;