在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,
),

有什么建议吗?

推荐答案

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

Dart相关问答推荐

Dart中的运算符(){…}做什么?

创建默认应用时 FirebaseOptions 不能为空

触发从小部件到状态对象的函数

一键式 Flutter 工具提示

ProcessException:进程C:\..\myapp\android\gradlew.bat异常退出:

Flutter DatePicker 没有day选项

如何等待forEach完成异步回调?

如何限制TextSpan小部件的文本长度

替换 Flutter 中的片段等小部件

Flutter类继承

如何使用flatter删除Firestore文档中的字段

Flutter:按下按钮时播放声音

Dart 中 http 和 HttpClient 的区别

Dart 转换列表的每个元素

DART:future的语法 then

是否有任何官方计划在 Google App Engine 上支持 Dart?

如何在 Dart 中扩展列表?

找不到名为pubspec.yaml的文件

Dart 中的with关键字

dart中的动态和对象有什么区别?