I have a function, which I want to return a Future of String or null. For simplicity, the function will return null if delay for 1 second is success, or else it will return "failed";
However; I got the
Future<String?> fcn(String str) {
return Future.delayed(const Duration(seconds: 1)).then((value) {
return null;
}).onError((error, stackTrace) {
return "failed"; // The return type 'String' isn't a 'FutureOr<Null>', as required by the closure's context.
});
}