Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Flutter calculate pixels for different resolutions?

Tags:

flutter

dart

Flutter apps can run on a variety of hardware, operating systems, and form factors. How are "pixels" calculated for different resolutions?

like image 674
Seth Ladd Avatar asked Jun 15 '17 16:06

Seth Ladd


People also ask

Does flutter use pixel?

Flutter owns every pixel on the screen. Cross-platform frameworks such as React Native and Xamarin. Forms which use native Android and iOS interface elements sound like a great idea, on paper: “ Write once and run anywhere!

What is pixel ratio in flutter?

double devicePixelRatio. The number of device pixels for each logical pixel for the screen this view is displayed on. This number might not be a power of two. Indeed, it might not even be an integer. For example, the Nexus 6 has a device pixel ratio of 3.5.

What are logical pixels?

Logical pixels are defined as the number of physical pixels in a device's screen divided by the CSS pixel ratio, and logical pixels are what you see when you look at your device (and more importantly, what your browser sees).


1 Answers

From https://api.flutter.dev/flutter/dart-ui/FlutterView/devicePixelRatio.html :

The number of device pixels for each logical pixel. This number might not be a power of two. Indeed, it might not even be an integer. For example, the Nexus 6 has a device pixel ratio of 3.5.

Device pixels are also referred to as physical pixels. Logical pixels are also referred to as device-independent or resolution-independent pixels.

By definition, there are roughly 38 logical pixels per centimeter, or about 96 logical pixels per inch, of the physical display. The value returned by devicePixelRatio is ultimately obtained either from the hardware itself, the device drivers, or a hard-coded value stored in the operating system or firmware, and may be inaccurate, sometimes by a significant margin.

The Flutter framework operates in logical pixels, so it is rarely necessary to directly deal with this property.

like image 137
Seth Ladd Avatar answered Nov 08 '22 20:11

Seth Ladd