0

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

1
  • Did you try to remove the const ? Commented Dec 22, 2019 at 10:24

1 Answer 1

2

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.