title: How do method cascades work exactly in dart?
body: <p>As stated in the dart article:</p>
  
  <blockquote>
    <p>The ".." syntax invokes a method (or setter or getter) but discards the result, and returns the original receiver instead.</p>
  </blockquote>
  
  <p>So I assumed that this would work:</p>
  
  <pre class="lang-dart prettyprint-override"><code>myList..clear().addAll(otherList);
  </code></pre>
  
  <p>which gave me the error that I can't call <code>.addAll</code> on <code>null</code>.</p>
  
  <p>So apparently <code>.</code> precedes <code>..</code> so that <code>.addAll</code> has been invoked on the <strong>result</strong> of <code>.clear()</code>.</p>
  
  <p>I figure now that I have two possibilities to write this:</p>
  
  <ol>
  <li><code>myList..clear()..addAll(otherList);</code></li>
  <li><code>(myList..clear()).addAll(otherList);</code> (If I wanted to get the result of <code>.addAll()</code>.</li>
  </ol>
  
  <p>Is this correct? If yes, why the decision to give <code>.</code> precedence? It seems very counterintuitive. Is it to avoid syntax like this: <code>myList(..clear().useResultOfClear()).addAll(otherList);</code>?</p>