Flutter: how to get DPI of device screen

7,712 views
Skip to first unread message

Luca Dal Poz

unread,
Nov 12, 2019, 5:24:36 AM11/12/19
to Flutter Development (flutter-dev)

Is there a way to get the actual value of screen DPI in Flutter (Dart)??


I need that value to calculate many other stuffs, and so it's not enought for me to use integrated Flutter features about responsiveness.

I really need a raw DPI value


I mean for example like: 

MediaQuery.of(context).dpi //but it doesn't exists


Thank you so much

Reme Le Hane

unread,
Nov 12, 2019, 5:50:32 AM11/12/19
to Flutter Development (flutter-dev)
MediaQuery.of(context).devicePixelRatio

You were like right there, ctrl+space would have brought up a list of options on MediaQuery.of(context).

Luca Dal Poz

unread,
Nov 12, 2019, 6:05:57 AM11/12/19
to Flutter Development (flutter-dev)
Thank you, but I already knew about ctrl+space and I already knew about MediaQuery.of(context).devicePixelRatio
but unfortunately it's value is not what I'm actually looking for.

I give you an example:

    MediaQuery.of(context).devicePixelRatio = 2.625 (in my device)

but I'm looking for a value that is tipically greater than 100 like 420dpi

... so how you can see those values are quite differents

Мурат Байсангуров

unread,
Nov 12, 2019, 9:54:51 AM11/12/19
to Flutter Development (flutter-dev)
You should multiply this value by 160 (dpi with devicePixelRatio = 1) and you will get your real dpi value

вторник, 12 ноября 2019 г., 14:05:57 UTC+3 пользователь Luca Dal Poz написал:

Benedicte Roussel

unread,
Nov 12, 2019, 1:00:43 PM11/12/19
to Flutter Development (flutter-dev), Мурат Байсангуров
To calculate screen density, you can use this equation:
Screen density = Screen width (or height) in pixels / Screen width (or height) in inches
104 19,685 5,283210566
208 39,3701 5,283197147



Le mardi 12 novembre 2019 à 15:54:59 UTC+1, Мурат Байсангуров <b.mo...@gmail.com> a écrit :


You should multiply this value by 160 (dpi with devicePixelRatio = 1) and you will get your real dpi value

вторник, 12 ноября 2019 г., 14:05:57 UTC+3 пользователь Luca Dal Poz написал:
Thank you, but I already knew about ctrl+space and I already knew about MediaQuery.of(context). devicePixelRatio
but unfortunately it's value is not what I'm actually looking for.

I give you an example:

    MediaQuery.of(context). devicePixelRatio = 2.625 (in my device)

but I'm looking for a value that is tipically greater than 100 like 420dpi

... so how you can see those values are quite differents


Il giorno martedì 12 novembre 2019 11:50:32 UTC+1, Reme Le Hane ha scritto:
MediaQuery.of(context).deviceP ixelRatio

You were like right there, ctrl+space would have brought up a list of options on MediaQuery.of(context).

On Tuesday, 12 November 2019 12:24:36 UTC+2, Luca Dal Poz wrote:

Is there a way to get the actual value of screen DPI in Flutter (Dart)??


I need that value to calculate many other stuffs, and so it's not enought for me to use integrated Flutter features about responsiveness.

I really need a raw DPI value


I mean for example like: 

MediaQuery.of(context).dpi //but it doesn't exists


Thank you so much

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/flutter-dev/a061263f-c8ef-429e-a08d-3592d5aa4d51%40googlegroups.com
.
Reply all
Reply to author
Forward
0 new messages