0

Does the Dart language have anything better to handle the potential of the callback being null than I have done here:

if(widget.onChanged!=null){
                   widget.onChanged!(value);
                 }
Gwhyyy
  • 7,554
  • 3
  • 8
  • 35
Xander
  • 9,069
  • 14
  • 70
  • 129

1 Answers1

1

In case onChanged is of type Function, you can use

onChanged?.call(value);

This will only call the function if it is not undefined/null.

Thomas
  • 2,375
  • 2
  • 17
  • 32