Reputation: 12433
How do I specify that subtypes can implement a function if they want to, but if they don't implement it, it will be null?
I want to do this:
// base class member
Future<dynamic> vpSubmitLocalMethod()?;
// in a function in the same base class:
if (vpSubmitLocalMethod != null) {
vpSubmitLocalMethod!();
}
Is this possible? Or if not, what is the cleanest solution? Or do I have to create an extra boolean class member to use in the if statement?
Upvotes: 1
Views: 157
Reputation: 1814
You can try this solution: create
typedef SubmitLocal = Future Function();
In your class, create a field :
SubmitLocal? vpSubmitLocalMethod;
And you use :
vpSubmitLocalMethod?.call();
Upvotes: 1