title: insert value at specific index in empty list dart
body: <p>I want to add element at specific index in empty list dart like the following</p>
  <pre><code>List values = List();
  values[87] = {'value': 'hello'};
  
  </code></pre>
  <p>When I try to run this code it shows this error</p>
  <pre><code>Unhandled Exception: RangeError (index): Invalid value: Valid value range is empty: 87
  </code></pre>
  <p>The solution is to set the list length <code>List values = List(100);</code> but the problem is I dont know the length because the index is the id, it can be 87 or 1523 .... so I can not set the length.</p>
  <p>Another solution is to use <code>final sparseList = SplayTreeMap&lt;int, dynamic&gt;();</code>
  and insert the element <code>sparseList[87] = {'value': 'hello'};</code></p>
  <p>The problem with SplayTreeMap is I cannon do jsonencode or json.encode to this type of list, it shows this error msg</p>
  <pre><code>Unhandled Exception: Converting object to an encodable object failed: Instance of 'SplayTreeMap&lt;int, dynamic&gt;'
  </code></pre>
  <p>Questions:</p>
  <p>1- How to set element at a specific index in empty list in dart?</p>
  <p>2- How to json encode  a SplayTreeMap  list to send it to the server to php file.</p>
  <p>Thanks</p>