How to use short if in flutter
this code can use:
1 + 1 == 2 ? print('check true') : print('check false');
Ans. print('check true')
but I want to do this:
1 + 1 == 2 ?? print('check true');
Why code can't print check true?
How to use short if in flutter
this code can use:
1 + 1 == 2 ? print('check true') : print('check false');
Ans. print('check true')
but I want to do this:
1 + 1 == 2 ?? print('check true');
Why code can't print check true?
Simply
1 + 1 == 2 ? print('check true') : print('check false');
is equals to
if(1+1 == 2) {
print('check true');
else {
print('check false');
}
and
1 + 1 == 2 ?? print('check true');
is equals to
if((1+1 == 2) == null ) {
print('check true');
}
1 + 1 == 2 ?? print('check true');. This does not work. ?? provides a default value in case the expression to the left is null