【问题标题】:Conditional padding inside Flutter widgetFlutter 小部件内的条件填充
【发布时间】:2021-01-28 04:44:47
【问题描述】:

我看到this 条件颜色的答案

我正在尝试对这样的填充做同样的事情

Padding(
  padding: const EdgeInsets.only(bottom: isLogin ? 58.0 : 10.0),
)

它没有被接受。

谢谢

【问题讨论】:

  • 那是因为您使用了关键字“const”,但您考虑的是变量……常量不能改变。

标签: flutter flutter-layout flutter-padding


【解决方案1】:

你可以这样使用它:

            padding: isLogin
                ? EdgeInsets.only(bottom: 58.0)
                : EdgeInsets.only(bottom: 10.0),

编辑:

或者像这样删除const。

            padding: EdgeInsets.only(bottom: isLogin ? 58.0 : 10.0),

您可以从here 阅读const 的用法。

【讨论】:

  • 非常感谢
猜你喜欢
  • 2021-11-28
  • 2022-08-23
  • 2020-02-22
  • 2020-06-29
  • 2021-07-14
  • 1970-01-01
  • 2021-11-13
  • 2020-12-11
  • 2021-05-23
相关资源
最近更新 更多