How to use ternary operator in Flutter / Dart

1

How to do if/else on a line in Dart / Flutter ?

Type: variavel ? null : function() : function2()

    
asked by anonymous 05.03.2018 / 17:33

1 answer

1

You can do this:

Comparison ? Value if true : Value if false ;

Ex:

void main() {
    for (int i = 0; i < 5; i++) {
        var result = i % 2 == 0 ? print("$i - par") : print("$i - impar");
    }
}
    
05.03.2018 / 20:07