dunil
dunil

Reputation: 33

Flutter if statement inside a Text Widget without an else

I am trying to display data from the database while some conditions are met, I am not sure if it is possible to use a while loop inside of a Text Widget, so I am using this code. However, by using this code, it forces me to write a value of text if the statement is not met, but instead I would like to skip those data if condition is not met and don't display anything, and null does not work inside of the Text widget. I was also wondering if there is a way to use a while loop inside a Text Widget?

Text(
   widget.userId == chats.senderid ||
   widget.userId == chats.receiverid ?
   chats.messageCont,
);

Upvotes: 2

Views: 994

Answers (1)

Amon C
Amon C

Reputation: 1808

Do like this:

widget.userId == chats.senderid ||
   widget.userId == chats.receiverid ? Text(chats.messageCont): Container()

Upvotes: 2

Related Questions