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?
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).
You can't use both const
constructor and dynamic content.
Do new EdgeInsets.only(
instead
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With