Flutter 能否可靠地呈现“0.5”宽的线条?

Can Flutter reliably render "0.5"-width lines?

在设计用户体验时,我发现有时 0.5 宽度的线是合适的。例如,Divider(thickness: 0.5).

但是,我想知道这是否可以在所有类型的设备中可靠地呈现?例如,它会在某种设备上完全消失吗?

感谢您的任何建议!

是的,在低密度屏幕上可能看不到线条。例如,尝试在您的设备上画一条 0.001 线。它会消失。

通过使用 devicePixelRatio 可以防止线条变得小于 1px。

import 'dart:math' as math;

final pixelPerPoint = MediaQuery.of(context).devicePixelRatio;
final onePixelSize = 1 / pixelPerPoint;
return Divider(
  thickness: math.max(0.01, onePixelSize),
);
/// 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.
final double devicePixelRatio;