I'm trying to assign certain values to some of the properties based on the input value. The value remains the same throughout the widget's life cycle. Therefore I used Stateless widget. But, I can't assign a value for the props from the constructor.
class InOrOut extends StatelessWidget {
final Condition condition;
final bool isIconVisible;
final Color backgroudColor;
final Color foregrounndColor;
InOrOut({Key key, this.condition, this.isIconVisible}) : super(key: key) {
switch (condition) {
case Condition.IN:
backgroudColor = Colors.green[100];
foregrounndColor = Colors.green[100];
isIconVisible = false
break;
case Condition.ABSENT:
backgroudColor = Colors.grey[300];
foregrounndColor = Colors.green[100];
isIconVisible = true;
break;
case Condition.OUT:
backgroudColor = Colors.red[100];
foregrounndColor = Colors.green[100];
isIconVisible = false;
break;
default:
backgroudColor = Colors.red[100];
foregrounndColor = Colors.green[100];
isIconVisible = false;
}
}
The following error comes when trying to assign a value to prop:
'foregrounndColor' can't be used as a setter because it is final. Try finding a different setter, or making 'foregrounndColor' non-final.dart(assignment_to_final)
If I remove final I can't use it inside the Stateless widget.
Finally, should I change to Stateful widget just because of this?