This should be an easy answer but I do not find the solution yet on the internet.
Let say I have 1 VoidCallback
field name onStart
in a constructor, and I want this field to have a default value when there is no parameter pass it to the constructor. I already try some code but the IDE gives me a warning. How to provide this default value?
class DefaultCallbackExample {
final VoidCallback onStart;
final VoidCallback onFinish;
final bool isEnable;
DefaultCallbackExample({
this.onStart = (() => {}), // IDE Warning
required this.onFinish,
this.isEnable = true,
});
}
class DefaultCallbackExample {
final VoidCallback onStart;
final VoidCallback onFinish;
final bool isEnable;
DefaultCallbackExample({
this.onStart = const (() => {}), // IDE Warning
required this.onFinish,
this.isEnable = true,
});
}
There is a solution from jamesdin, but I hope there is a simpler solution not to have to write constant sentinel value
. Maybe in the future dart version, there is a possible solution