user13427040
user13427040

Reputation:

How to describe absence of value in dart?

In the turnary operator statement 5 == 5 ? print('Correct') : print('Wrong'), I want the statement to return nothing(You can see it's returning a print statement) if the evaluation of the initial expression turns false, how do I do that?

The actual code is given below, the return type cannot be null. So, that isn't an option

Column(
   mainAxisAlignment: MainAxisAlignment.spaceAround,
   children: <Widget>[
     Text(times[index]),
     newMessagehasCome ? Icon(Icons.laptop) ? 
   ], 
)

Upvotes: 0

Views: 63

Answers (1)

julemand101
julemand101

Reputation: 31289

You can do it like this if you project supports Dart 2.3.0 or later:

Column(
   mainAxisAlignment: MainAxisAlignment.spaceAround,
   children: <Widget>[
     Text(times[index]),
     if (newMessagehasCome)
       Icon(Icons.laptop)
   ], 
)

Upvotes: 1

Related Questions