dart - Flutter.io (dart) - 如何创建左填充覆盖?

在 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(

https://stackoverflow.com/questions/47165288/

相关文章:

android - 在模拟器相机应用程序中看不到虚拟场景图像

dart - Flutter popUntil 抛出Bad state : Future alrea

firebase - Flutter 中的 cloud_firestore 和 firebase_a

flutter - 找不到名为 "split-per-abi"的选项

flutter - 根据另一个小部件的位置/大小定位/调整小部件的大小

dart - Flutter - 在底部绘制一个矩形

android - 在 dart/flutter 项目中包含 C 文件

dart - Flutter:测试是否抛出了特定的异常

dart - Flutter - 动态构建小部件

Flutter - 屏幕的多个文件?