Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is unit of measurement in flutter

as usual, we use dp for Android and pt(point) for ios as a unit of measurement.

1 pt = 1/72 inch

1 dp = 1/160 inch

But i don't what is unit of measurement in flutter

example:

SizedBox(height: 16.0)

or

TextStyle(fontSize: 23.0)

It just a double number, how many dp or pt equal to 1.0 (flutter)? How is it calculated?

like image 346
Khánh Vũ Đỗ Avatar asked May 30 '18 03:05

Khánh Vũ Đỗ


People also ask

What are logical pixels flutter?

Logical pixels are roughly the same visual size across devices. Physical pixels are the size of the actual hardware pixels on the device. The number of physical pixels per logical pixel is described by the devicePixelRatio.

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).


2 Answers

From https://docs.flutter.io/flutter/dart-ui/Window/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 87
Tree Avatar answered Sep 28 '22 02:09

Tree


The unit of measure in Flutter is Logical Pixels. Logical Pixels are equivalent to cm or inches and do not vary depending on the resolution the same way a ruler doesn't.

1 cm = 38 logical pixels

1 in = 96 logical pixels

Logical pixels are different from device (also called physical) pixels. Device/physical pixels are the number of dots/points in the display that emit light.

This numbers were chosen for historic reasons and come from 1980. Source: Microsoft

like image 25
Roddy R Avatar answered Sep 28 '22 01:09

Roddy R