2

I'm getting an error when assigning a default value to an instance variable of the type Color. I'm getting this error only when I assign colors with their shade value.

Error: The default value of an optional parameter must be constant.

class CardPanelHeader extends StatelessWidget {
  final String leadingPanelText;
  final Color leadingPanelTextColor;
  final String trailingPanelText;
  final Color trailingPanelTextColor;

  const CardPanelHeader({
    Key key,
    this.leadingPanelText,
    this.leadingPanelTextColor = Colors.black87,
    this.trailingPanelText,
    this.trailingPanelTextColor = Colors.grey.shade600,
  }) : super(key: key);

I did check this solution but didn't work for me.

Could anyone please help me with this. Thanks in advance!

Henok
  • 3,293
  • 4
  • 15
  • 36
xpetta
  • 607
  • 12
  • 28

1 Answers1

3

You can use absolute value of the color as constant value; change the Colors.grey.shade600 to const Color(0xFF757575) you can find the hex code of colors https://material.io/resources/color/

Mehmet Ali Bayram
  • 7,222
  • 2
  • 22
  • 27