I write the following widget:
class Bottombar extends StatelessWidget {
final double padding;
Bottombar({@required this.padding});
@override
Widget build(BuildContext context) {
return new Container(
padding: const EdgeInsets.all(padding), child: new Text('Test'),);
}
}
However, it reports compiling error that the padding parameter must be constant expressions. Why cannot use the final member field as the parameter of widget padding? For what reason?
The flutter version is beta 0.3.1
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).
The main difference between the padding and margin is: Padding provides the space between the border and the content of an element. Margin provides the space between the border and outer elements.
You can create a seperate class that creates the buttons and specify the padding once. Then you can call that class again and again to create as many buttons as you want in the Column. Now you don't need to specify the padding for the Column and the Row will not have any padding. Save this answer.
The problem is you're using const
to create the EdgeInsets
but then passing a variable padding
.
Remove const
and it should work.
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