How to check for null in Dart?
<p>I don't know what I am doing wrong. I thought that to check whether a variable <code>x</code> is <em>not</em> <code>null</code> in Dart, one could simply do <code>x != null</code>. But that does not work in this code below. And, it is not clear to me why. I would appreciate why it is not working.</p>

<pre><code>void getUserAnswers() {

  HttpRequest.getString(pathToUserAns).then((String data) {

    print("data is: $data");

    if (data != null) {
      print("data is not null");
    }

  });
}
</code></pre>

<p>The above code gives the following output in the chromium console:</p>

<pre><code>data is: null

data is not null
</code></pre>

<p>which does not seem to make sense.</p>