title: Flutter/Dart - Split Comma Separated String into 3 Variables?
body: <p>I've got a comma-separated string of tags, IE &quot;grubs, sheep, dog&quot;. How can I separate this into three variables? I tried ;</p>
  <pre><code>var splitag = tagname.split(&quot;,&quot;);
  var splitag1 = splitag[0];
  var splitag2 = splitag[1];
  var splitag3 = splitag[2];
  </code></pre>
  <p>But if any of the variables are null it throws an error. So I tried;</p>
  <pre><code>String splitagone = splitag1 ?? &quot;&quot;;
  String splitagtwo = splitag2 ?? &quot;&quot;;
  String splitagthree = splitag3 ?? &quot;&quot;;  
  </code></pre>
  <p>But I got the same error. So is there another way I can check that the tag is not null and use the variable?</p>
  <pre><code>if(tagname != null) {
        tagname.split(',').forEach((tag) {       
        //  something?    
        });
      }
  </code></pre>