title: How to save and retrieve a list of custom objects with SharedPreferences?
body: <p>I'm making a Flutter app for fuel expenses tracking. I have a simple object:</p>
  
  <pre><code>class Entry {
    double _fuel;
    double _money;
    double _distance;
  
    Entry(this._fuel, this._money, this.distance);
  
    Entry.fromJson(Map&lt;String, dynamic&gt; json) =&gt; Entry (json['fuel'], json['money'], json['distance']);
  
    Map&lt;String, dynamic&gt; toJson() =&gt; {'fuel':_fuel, 'money':_money, 'distance':_distance};
  }
  </code></pre>
  
  <p>Whenever I refill my tank I want to make a new entry and to keep all of them virtually forever. In the app I have a <code>List&lt;Entry&gt; entries</code>, but I couldn't find a way to save that list in <code>SharedPreferences</code>. There is only a method which accepts a list of Strings. Should I create a new <code>List&lt;String&gt;</code> by iterating through my <code>List&lt;Entries&gt;</code> and serializing each entry, and then saving that list to the <code>SharedPreferences</code> or is there an easier way? And when I want to read from <code>SharedPreferences</code>, how can I recreate my list?</p>
  
  <p>Update: Of course, I also need to be able to delete a particular entry from the list.</p>
  
  <p>Thanks.</p>