title: Flutter/Dart return Future<String?>
body: <p>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 &quot;failed&quot;;</p>
  <p>However; I got the</p>
  <pre><code>  Future&lt;String?&gt; fcn(String str) {
      return Future.delayed(const Duration(seconds: 1)).then((value) {
        return null;
      }).onError((error, stackTrace) {
        return &quot;failed&quot;; // The return type 'String' isn't a 'FutureOr&lt;Null&gt;', as required by the closure's context.
      });
    }
  </code></pre>