Here's the ugly long code:
var i;
if(true)
i = 1;
else
i = 0;
When I try this:
var i = (true ? 0 : 1);
it doesn't work resulting in an error on the following line. I guess I was a bit inattentive reading Dart's syntax specs, so can anybody show me the right way?
This error happened because the text property of the TestModel class is final. Final objects arent meant to be changed in Flutter. to fix this problem you should go to the TestModel class and remove final from the text property.
This looks perfectly fine from a syntax point of view. You can omit the parentheses.
I get a warning 'Dead code' at '1' with your example because of 'true'.
The Darteditor shows you a hint that you wrote code that may contain a bug because he knows your expression can never evaluate to 1 because of the hardcoded 'true'.
void main(List<String> args) {
var b = true;
var i = b ? 0 : 1;
}
doesn't produce a warning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With