Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

flutter

dart

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?

like image 750
Deborah Avatar asked Nov 07 '17 18:11

Deborah


People also ask

How do you set a padding Flutter?

But in Flutter, if you want add some extra space around a widget, then you wrap it in a Padding widget. Now to add padding, wrap the Text widget with a Padding widget. In Android Studio this can be accomplished by placing your cursor on the widget and pressing Option+Enter (or Alt+Enter in Windows/Linux).


1 Answers

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

like image 69
Rémi Rousselet Avatar answered Oct 21 '22 00:10

Rémi Rousselet