【问题标题】:Flutter should I specify size in int or double?Flutter 我应该用 int 还是 double 指定大小?
【发布时间】:2023-01-19 20:53:04
【问题描述】:

在 flutter 中指定小部件大小时,我应该使用整数还是双精度数?例如,它应该是SizedBox(width:8),还是SizedBox(width:8.0)

我试着查看 flutter 文档,但找不到任何相关信息,所以我寻找示例:https://docs.flutter.dev/development/ui/layouthttps://api.flutter.dev/flutter/widgets/SizedBox-class.html,但它们似乎不一致......

【问题讨论】:

  • 最终它将在编译器端转换为浮点数。你可以通过你喜欢的那个。如果你只是通过8,输入.0需要额外的时间,我不喜欢输入这个。

标签: flutter


【解决方案1】:

当你想设置round值时,你不需要使用double,否则你需要它。

【讨论】:

    【解决方案2】:

    如果你进入 SizedBox,你会看到一个 Double 等在那里。当您键入 8 时,SizedBox 无论如何都会将其视为 8.0。

    在 SizedBox 里面是

    const SizedBox({ super.key, this.width, this.height, super.child });
    const SizedBox.expand({ super.key, super.child })
        : width = double.infinity,
          height = double.infinity;
    

    【讨论】:

      猜你喜欢
      • 2010-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-14
      • 2021-10-18
      • 1970-01-01
      • 2019-08-24
      • 1970-01-01
      相关资源
      最近更新 更多