How to create a default empty function in Dart

Viewed 1046

I want to pass a callback as a constructor parameter and if the callback is null I want to give a default value. But I don't know a proper way how to generate an empty function in Dart.

enter image description here

2 Answers

You need to wrap the callback in parentheses:

this.callback = callback ?? (() {})

otherwise the braces would be considered as the body of the constructor.

Just remove the arrow function so you have this.callback = callback ?? () {}

Related