首页 > 解决方案 > Drawing a shape with dimensions in millimeters

问题描述

I have dimensions in millimeters (mostly rectangles and squares) and I'm trying to draw them to their size.

Something like so 6.70 x 4.98 x 3.33 mm.

I really won't be using the depth in the object but just threw it in.

New to drawing shapes with my hands ;)

标签: flutterdrawshapes

解决方案


屏幕通常以像素 (android) 或点 (ios) 为单位。两者都达到了 72 分/英寸的旧标准。不过,现在我们拥有具有不同像素比率的设备。要确定确切的尺寸,您需要确定当前设备的屏幕尺寸及其像素比率。两者都可以使用 WidgetsBinding.instance.window 完成...然后您只需从那里进行数学运算即可将这些测量值转换为 mm。

然而,这似乎是一个奇怪的要求,所以您可能只是在问如何绘制一个精确大小的正方形。您可能想查看可与 CustomPainter 结合使用的 Canvas/Paint API。另一种选择是带有一些 Position.fromRect 或 .fromRelativeRect 的 Stack 并使用该设置绘制它们。


推荐阅读