rozerro
rozerro

Reputation: 7156

Using if-else in build method

How can I use if-else construction in build method? Now I use double if:

if (_rapport.isNotEmpty && _rapport.length == 3)
  Container(
    child: Text(_rapport),
  ),
if (_rapport.isEmpty || _rapport.length != 3)
  const Text('wrong input'),

while using else brings the error:

enter image description here

Upvotes: 0

Views: 176

Answers (1)

tvl
tvl

Reputation: 100

You can use a ternary if-statement. condition ? true : false;

With context: 5 > 1 ? print("this will be printed") : print("this won't be printed");

https://medium.com/run-dart/dart-dartlang-introduction-if-else-conditional-statement-1350a56e2e98?

Upvotes: 2

Related Questions