5

In some languages like Swift if you have Optional variable like below

var onItemPressed: ((Item) -> Void)?

// we can call this variable (function) like this
onItemPressed?(Item())

What's the equivalent of this in Dart language?

0

1 Answer 1

12

The equivalent in Dart would be the call method on functions.

Like this,

onItemPressed?.call(Item())

So basically, whenever your onItemPressed is null, the execution short-circuits itself and it won't be called resulting in avoiding the crash.

1

Not the answer you're looking for? Browse other questions tagged or ask your own question.