flutter - 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 ;)
解决方案
屏幕通常以像素 (android) 或点 (ios) 为单位。两者都达到了 72 分/英寸的旧标准。不过,现在我们拥有具有不同像素比率的设备。要确定确切的尺寸,您需要确定当前设备的屏幕尺寸及其像素比率。两者都可以使用 WidgetsBinding.instance.window 完成...然后您只需从那里进行数学运算即可将这些测量值转换为 mm。
然而,这似乎是一个奇怪的要求,所以您可能只是在问如何绘制一个精确大小的正方形。您可能想查看可与 CustomPainter 结合使用的 Canvas/Paint API。另一种选择是带有一些 Position.fromRect 或 .fromRelativeRect 的 Stack 并使用该设置绘制它们。
推荐阅读
- flutter - 我想放置一个自定义小部件来代替 appbar,并希望在它下面有一个标签视图
- javascript - 如何将索引号传递给反应类?
- python - 一些 Keras 预训练的网络在使用之前是否需要特殊的预处理?
- c# - .NET Core - HTTPClient - Ubuntu 20.04 上的 dh 密钥太小
- c++ - 如何让“make”知道其他目录的变化?
- javascript - 使用变量值作为角度标签属性值
- python - 列表无法识别 Plotly
- microsoft-graph-api - 适用于 Azure B2B 的 ASP.net 应用程序的 MS Graph 的 ADAL 或 MSAL
- amazon-web-services - 除了 AssumeRole 之外,还需要哪些权限才能在 AWS 控制台中将角色切换到另一个账户?
- reactjs - 如何在 React Router v6 中根据路由更改或参数创建动态子标题?