title: How to fix "The operator ‘{0}’ can’t be unconditionally invoked because the receiver can be ‘null’"
body: <p>While trying <strong>Dart</strong>'s <em>Sound Null Safety</em> i came up with a problem:</p>
  <hr />
  <h2>Some Context</h2>
  <p>Creating a new <strong>Flutter</strong> project i found the following (and very familiar) piece code</p>
  <pre class="lang-dart prettyprint-override"><code>int _counter = 0;
  
  void _incrementCounter() {
    setState(() {
      // This call to setState tells the Flutter framework that something has
      // changed in this State, which causes it to rerun the build method below
      // so that the display can reflect the updated values. If we changed
      // _counter without calling setState(), then the build method would not be
      // called again, and so nothing would appear to happen.
      _counter++;
    });
  }
  </code></pre>
  <p>Now, i changed the variable <code>_counter</code> to be <em>nullable</em> and took off the initialization:</p>
  <pre class="lang-dart prettyprint-override"><code>int? _counter;
  
  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }
  </code></pre>
  <p>And as expected, i got the following error in the editor:</p>
  <blockquote>
  <p>The operator ‘+’ can’t be unconditionally invoked because the receiver can be 'null'</p>
  </blockquote>
  <h2>The Problem</h2>
  <p>Following <a href="https://dart.dev/tools/diagnostic-messages#unchecked_use_of_nullable_value" rel="noreferrer">the documentation</a> i added the required checking:</p>
  <pre class="lang-dart prettyprint-override"><code>if (_counter!=null)
          _counter++;
  
  </code></pre>
  <p>but to my astonishment, the error kept on showing and suggesting</p>
  <blockquote>
  <p>Try making the call conditional (using '?' or adding a null check to the target ('!'))</p>
  </blockquote>
  <p>even though i explicitly am making <em>the call conditionally</em>... so what is wrong?</p>