title: Flutter/Dart - How to process Json data which contains a comma separated list?
body: <p>I've got a <code>PageViewBuilder</code> which uses a <code>Map&lt;String&gt;</code> of json data containing a String called <code>name</code> and another called <code>tagname</code>. The problem is that the <code>tagname</code> string is actually a comma-separated list of three tags which print out as &quot;boat,grass,toads&quot;; But I'd like to separate this String so that I can make each item a clickable button. IE:</p>
  <pre><code>FlatButton( onPressed: () =&gt; boat(),
                text: &quot;boat&quot;, 
              );
  
  FlatButton( onPressed: () =&gt; grass(),
                text: &quot;grass&quot;, 
              );
  
  FlatButton( onPressed: () =&gt; toads(),
                text: &quot;toads&quot;, 
              );
  </code></pre>
  <p>I tried to using Dart's split function like this;</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 this gives an error if any of the three tag names are void.</p>
  <p>So I tried this;</p>
  <pre><code>String splitagone = splitag1 ?? &quot;&quot;;
  String splitagtwo = splitag2 ?? &quot;&quot;;
  String splitagthree = splitag3 ?? &quot;&quot;;
  </code></pre>
  <p>But this still gave me an error. So can anyone suggest a different way to accomplish what I need? Here's the full code;</p>
  <pre><code>  class SpeakContent {
    final String name, tagname;
  
    SpeakContent({
      this.name,
      this.tagname
    });
  
    factory SpeakContent.fromJson(Map&lt;String, dynamic&gt; jsonData) {
      return SpeakContent(
        name: jsonData['name'],
        tagname: jsonData['tagname'],
      );
    }
  }
  
   class StageBuilder extends StatelessWidget {
  
    final List&lt;SpeakContent&gt; speakcrafts;
    StageBuilder(this.speakcrafts);
  
    @override
    Widget build(context) {
      return PageView.builder(
        itemCount: speakcrafts.length,
        itemBuilder: (context, int currentIndex) {
          return createViewItem(speakcrafts[currentIndex], context);
        },
      );
    }
  
    Widget createViewItem(SpeakContent speakcraft, BuildContext context) {
  
      return Column(
        children: &lt;Widget&gt;[
          Container(
            child: Text(
              speakcraft.name,
            ),
          ),
          Container(child:
              FlatButton( onPressed: () =&gt; boat(),
                child: Text('boat'),
              ),
          ),
          Container(child:
          FlatButton( onPressed: () =&gt; grass(),
            child: Text('grass'),
          ),
          ),
          Container(child:
          FlatButton( onPressed: () =&gt; toads(),
            child: Text('toads'),
          )
          ),
        ],
      );
    }
  }
  </code></pre>