Reputation: 1160
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.
Upvotes: 3
Views: 2890
Reputation: 1409
You need to wrap the callback in parentheses:
this.callback = callback ?? (() {})
otherwise the braces would be considered as the body of the constructor.
Upvotes: 3
Reputation: 1
Just remove the arrow function so you have this.callback = callback ?? () {}
Upvotes: 0