Callback function with returnvalue
void main() async {
String output = await function1();
print(output);
}
Future<String> function1() async {
print('[Start] function1');
String str = await function2(callback: callback);
print('[End] function1 | returnvalue from function2=$str');
return str;
}
Future<String> function2({required Function callback}) async {
print('[Start] function2');
String ret = await callback();
print('[End] function2');
return ret;
}
Future<String> callback() async {
print('[Start] callback');
await Future.delayed(Duration(seconds: 3));
print('[End] callback');
return 'ABC';
}