Home > Mobile >  Why is this if else statement showing an error ? - Flutter
Why is this if else statement showing an error ? - Flutter

Time:08-16

why is this showing an error ?, I am trying to change the color of the unread chats with an if else condition but it is showing an error. Error: Invalid constant value

CodePudding user response:

you have always to put the error with your question, in your case, if you're working with null safety, then i think you have to change chat.unread to chat!.unread. i cannot provide any more solution without knowing the exact error.

CodePudding user response:

Remove const from BoxDecoration because value`(chat) will get on runtime.

enter image description here

And if chat is nullable try it like

color: chat!=null && chat!.unread? Colors.from(...): Colors.white,
  • Related