What is unit of measurement in flutter

后端 未结 3 829
执笔经年
执笔经年 2020-12-15 04:07

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 measu

相关标签:
3条回答
  • 2020-12-15 04:47

    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.

    0 讨论(0)
  • 2020-12-15 04:54

    It all breaks down to device pixel ratio. For instance:

    var pixelRatio = MediaQuery.of(context).devicePixelRatio; // 2
    

    And say you're using SizedBox with height: 10, like:

    SizedBox(height: 10);
    

    That means your SizedBox would be 2 * 10 = 20dp tall on that device.

    0 讨论(0)
  • 2020-12-15 05:05

    It is measured in pixels, as described here: https://docs.flutter.io/flutter/material/Material-class.html.

    0 讨论(0)
提交回复
热议问题