Flutter.io (dart) - how to create a left padding override?

Viewed 8174

In Flutter, a container has padding:

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

I want to be able to override "left".

If I do this, I get a runtime error:

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

this also gets a runtime error:

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

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

Suggestions?

1 Answers

You can't use both const constructor and dynamic content. Do new EdgeInsets.only( instead

Related