title: In flutter - how do I best handle and assign predetermined keys to nested lists/arrays in json
body: <p>I'm sending data over ble and have compacted the json strings. The json contains three arrays.</p>
  <pre><code>{&quot;b&quot;:false,&quot;l&quot;:261,&quot;a&quot;:[&quot;0.5&quot;,&quot;1.8&quot;,&quot;2.9&quot;,&quot;1.0&quot;]}
  </code></pre>
  <p>I have a model class of Notify. I need to create a model class for &quot;a&quot; that assigns a predefined key to each of the values in the list but I am not sure of the best way. The values always come in a specific order.</p>
  <pre><code>class Notify{
    bool b;
    int l;
    List&lt;String&gt; a;
  
    Notify({this.b, this.a, this.d, this.p});
  
    Notify.fromJson(Map&lt;String, dynamic&gt; json) {
    b = json['b'];
    l = json['l'];
    a = json['a'].cast&lt;String&gt;();
    }
  
    Map&lt;String, dynamic&gt; toJson() {
      final Map&lt;String, dynamic&gt; data = new Map&lt;String, dynamic&gt;();
      data['b'] = this.b;
      data['l'] = this.l;
      data['a'] = this.a;
      return data;
    }
  }
  </code></pre>
  <p>I get lost in the steps. In this class I think I need to:</p>
  <ol>
  <li>Turn the &quot;a&quot; array into a list.</li>
  <li>Convert the Strings to doubles.</li>
  <li>Convert to a Map providing a key of a0, a1, a2, a3 to the four items in the &quot;a&quot; list.</li>
  <li>Add four more items to the overall class/map based on a0-a3. Example: a4 = a0 * -1, a5 = a1 * -1, a6 = a2 * -1, a7 = a3.</li>
  <li>Make it available and usable to the Notify class.</li>
  </ol>
  <pre><code>    class A {
        double a0;
        double a1;
        double a2;
        double a3;
        double a4;
        double a5;
        double a6;
        double a7;
      
        A a;
      
        A({this.a0, this.a1, this.a2, this.a3, this.a4, this.a5, this.a6, this.a7});
      
        A.fromJson(List&lt;double&gt; json){
  // Do bring it in as a list?
          List&lt;double&gt; angleValuesList = List&lt;double&gt;.from(json);
          List&lt;String&gt; angleKeysList = ['a0', 'a1', 'a2', 'a3'];
          Map&lt;String, double&gt; angleMap = Map.fromIterables(angleKeysList, angleValuesList);
  // Then I map the first four values to a0-a3
          //now lost..... how do I get close to items 3-5?
          }
        }
  </code></pre>
  <p>I'm hoping my map looks like this so I can create an object from it and drop it in a stream. I receive this packet every 16 milliseconds:</p>
  <pre><code>{&quot;b&quot;:false,&quot;l&quot;:261,&quot;a&quot;:[&quot;a0&quot;: &quot;0.5&quot;, &quot;a1&quot;:&quot;1.8&quot;, &quot;a2&quot;:&quot;2.9&quot;, &quot;a3&quot;:&quot;1.0&quot;, &quot;a4&quot;: &quot;-0.5&quot;, &quot;a5&quot;:&quot;-1.8&quot;, &quot;a6&quot;:&quot;-2.9&quot;, &quot;a7&quot;:&quot;-1.0&quot;]}
  </code></pre>
  <p>Thanks for taking the time to read through this!</p>