I'm creating a card widget that will be used to create a list of cards. I want to pass a parameter isLastCard to each card, so that I can increase margin for the last card in the list.
I have the following setup:
class CardsIndex extends StatelessWidget {
Widget _card(context, label, bool isLastCard) {
const double bottomMargin = isLastCard ? 40.0 : 8.0;
return new Container(
margin: const EdgeInsets.fromLTRB(12.0, 8.0, 12.0, bottomMargin),
child: new Row(
children: <Widget>[
new Expanded(
child: new Text(label),
),
],
),
);
}
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Cards"),
),
body: new Container(
child: new Stack(
children: [
new Container(
child: new ListView(
children: <Widget>[
_card(context, 'Card 1', false),
_card(context, 'Card 2', false),
_card(context, 'Card 3', true),
],
)
)
],
),
),
);
}
}
This gives me this error in the output, for isLastCard inside the turnary:
Const variables must be initialized with a constant value.
How do I correctly define isLastCard and bottomMargin in the _card widget?
Thanks!