Android Display Metrics

All things Flutter

Android Display Metrics

I have been looking at trying to determine the form factor of Android devices via their physical screen size and found a lot of articles on doing various types of calculation using pixel count and DPI, the issue with Flutter, at least from my internet searches and queries, was the value was not available.  So I did some research and found out that DisplayMetrics seemed the way to go. 

I then ran through the  Flutter Platform Channels docs and demo and created a test app (based on the Flutter Battery Level demo) to extract the DPI from the device. In fact I ended up returned all the data that was available from DisplayMetrics. The complete app can be found here.

 

I have also be told of a much easier way of getting the DPI value I needed by @slightfoot using Flutter’s MediaQuery. This returns a value for devicePixelRatio which , if multiplied by the MDPI DPI value (160) . gives the device DPI. For example  the device below has a devicePIxelRatio of 3.5 , so multiply that by 160 and hey presto you get 560.

 

But still the project is valid and gave me a good insight into accessing Android from  Flutter.