Is it possible to get the device sizes in flutter?

Issue

I am building a flutter web app, and I would like to know the width of the device the app is running on, not the window. Is this possible? Thank you!

Solution

You can get it without access to BuildContext like this:

final double width = window.physicalSize.width / window.devicePixelRatio;
final double height = window.physicalSize.height / window.devicePixelRatio;

Make sure you import dart:ui, not the html library.

Answered By – Alexey Subbotin

Answer Checked By – Jay B. (FlutterFixes Admin)

Leave a Reply

Your email address will not be published.