Well, short answer, no (with the operator). The null-aware ?.
operator in Dart will work only with object call to members, not to null-check a function execution directly.
In this case bellow, it would work:
class MyClass {
Function(String s) onTextReady = (s) => print(s);
}
main() {
var nullObject;
nullObject?.onTextReady('null'); // do nothing
var notNull = MyClass();
notNull?.onTextReady('not null'); // print 'not null'
}
You would need to check it manually (!= null) to be null-safe:
main() {
Function(String) onTextReady;
if(onTextReady != null) {
onTextReady('null');
}
Function(String) onTextReady2 = (s) => print(s);
if(onTextReady2 != null) {
onTextReady2('not null');
}
}