【问题标题】:Can Flutter reliably render "0.5"-width lines?Flutter 能否可靠地渲染“0.5”宽的线条?
【发布时间】:2022-01-14 09:58:21
【问题描述】:

在设计 UX 时,我发现有时 0.5 宽的线条是合适的。例如,Divider(thickness: 0.5)

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

感谢您的任何建议!

【问题讨论】:

    标签: android ios flutter dart user-experience


    【解决方案1】:

    是的,这条线可能在低密度屏幕上不可见。例如,尝试在您的设备上画一条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;
    

    【讨论】:

    • 听起来不错,谢谢!
    猜你喜欢
    • 2018-08-29
    • 1970-01-01
    • 2013-12-23
    • 1970-01-01
    • 2021-12-12
    • 2021-11-14
    • 2023-04-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多