【问题标题】:Flutter.io (dart) - how to create a left padding override?Flutter.io (dart) - 如何创建左填充覆盖?
【发布时间】:2018-04-20 06:56:17
【问题描述】:

在 Flutter 中,容器具有填充:

padding: const EdgeInsets.only(
  left: MyMeasurements.globalLeftPadding,
  right: 20.0,
),

我希望能够覆盖“左”。

如果这样做,我会收到运行时错误:

class MySectionHeader extends StatelessWidget {
    final double left;

MySectionHeader({
  this.left,
});

// down to the widget body
padding: const EdgeInsets.only(
  left: left ?? MyMeasurements.globalLeftPadding,
  right: 20.0,
),

// and in the container that has the override...
new MySectionHeader(
  left: 12.0,
),

这也会出现运行时错误:

padding: const EdgeInsets.only(
  left: left ?? 14.0,
  right: 20.0,
),

// and in the container that has the override...
new MySectionHeader(
  left: 12.0,
),

建议?

【问题讨论】:

    标签: dart flutter


    【解决方案1】:

    您不能同时使用const 构造函数和动态内容。 改为new EdgeInsets.only(

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-29
      • 2014-07-23
      • 2013-10-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多