Question - How to declare async function as a variable in Dart?
Answer -
Async functions are normal functions with some sugar on top. The function variable type just needs to specify that it returns a Future:
class Example {
Future Function() asyncFuncVar;
Future asyncFunc() async => print('Do async stuff...');
Example() {
asyncFuncVar = asyncFunc;
asyncFuncVar().then((_) => print('Hello'));
}
}
void main() => Example();