title: Convert List<T> into json in flutter
body: <p>I have a list of option when the attribute is selected of a particular option then I save attribute object at the selected position of option in the list.
  now I have an option list with their selected attribute object. My aim is to convert the options list into JSON object but when the attribute is not null. The Attribute object can be null in that case when a person has not chosen an attribute of an option. </p>
  
  <pre><code>class OptionAttribute{
   String _grouprowid;
   String _groupname;
   Attribute _selectedAttrObject
  
     Map&lt;String, dynamic&gt; toJson() =&gt; {
      'attribute': _selectedAttrObject,
    };
  }
  
  class Attribute{
  
    String _attributerowid;
    String _grouprowid;
    String _attributename;
    String _weight;
  
     Map&lt;String, dynamic&gt; toJsonAttr() =&gt; {
      'attrid': _attributerowid,
      'groupid': _grouprowid,
      'attrname': _attributename
    };
  
  }
  </code></pre>
  
  <p>I want to convert below list into JSON object when the list does not have any null attribute.</p>
  
  <pre><code>List&lt;OptionAttribute&gt; opAtrrList=new List&lt;OptionAttribute&gt;();
  </code></pre>