I'm trying to understand how dart uses a function as parameter. I wrote this code...
typedef Future<String> myFunction();
void main() {
A a = A();
a.f1(a._f1);
}
class A {
f1(myFunction func) async {
String x = await _f1;
print(x);
}
Future<String> _f1() {
Future.delayed(Duration(seconds: 3)).then((f) {
return "test";
});
}
}
I need the function f1 returns "test", but I have this error : A value of type 'Future Function()' can't be assigned to a variable of type 'String'
If I change String x = await _f1 by Future x = await _f1 I have another error.. I tried a lot of combinations, all of them fail.
Can someone fix my code? Thank you.