4

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?

devAdam
  • 43
  • 2

1 Answers1

11

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.

Nisanth Reddy
  • 5,967
  • 1
  • 11
  • 29