The documentation says:
If the function has a declared return type, then update the type to be
Future<T>, whereTis the type of the value that the function returns.
When I do that with this code, I get an error: A value of type 'String?' can't be returned from the method 'amethod' because it has a return type of Future < String>?.
Why is it giving that error and what is the correct way to return a non-void value from an async function? Thanks.
class Demo{
Future<String>? amethod() async{
String? variable1;
//await ...
return variable1;
}
}