title: How to conditionally add widgets to a list?
body: <p>In flutter, widgets such as <code>Row</code>/<code>ListView</code>/<code>Stack</code> don't handle null children. So if we want to conditionally add widgets as children I usually do the following:</p>
  
  <pre><code>Row(
    children: &lt;Widget&gt;[
      foo == 42 ? Text("foo") : Container(),
    ],
  );
  </code></pre>
  
  <p>But this feels weird to add an empty container.</p>
  
  <p>Another solution is a <code>where</code> filter :</p>
  
  <pre><code>Row(
    children: &lt;Widget&gt;[
      foo == 42 ? Text("foo") : null,
    ].where((t) =&gt; t != null).toList(),
  );
  </code></pre>
  
  <p>This solves the empty container problem but we still have an ugly ternary and it is tiresome to write.</p>
  
  <p>Is there any better solution?</p>