title: Flutter - Sembast Database insert List of Objects
body: <p>I'm about to use the database "Sembast" in Flutter.
  Simple objects with data types like string and int are working properly. However, it becomes problematic when using Lists.</p>
  
  <p>I have created an example and oriented myself on the following tutorial: <a href="https://resocoder.com/2019/04/06/flutter-nosql-database-sembast-tutorial-w-bloc/" rel="nofollow noreferrer">https://resocoder.com/2019/04/06/flutter-nosql-database-sembast-tutorial-w-bloc/</a>
  In my example, there are fruits and leaves as objects. A fruit contains a list of leaves.</p>
  
  <pre class="lang-dart prettyprint-override"><code>class Fruit {
    final String id;
    final String name;
    final bool isSweet;
    final List&lt;Leaves&gt; leaves;
  ...
  }
  
  class Leaves {
    final String id;
    final String name;
  ...
  }
  
  //Create a sample object
  var leaveOne = Leaves(id: "1", name: "leaveOne");
  var leaveTwo = Leaves(id: "2", name: "leaveTwo");
  var leaveThree = Leaves(id: "3", name: "leaveThree");
  
  var leavesList = List&lt;Leaves&gt;();
  leavesList.add(leaveOne);
  leavesList.add(leaveTwo);
  leavesList.add(leaveThree);
  
  var fruit = Fruit(id: "1", name: "Apple", isSweet: true, leaves: leavesList);
  _fruitDao.insert(fruit);
  
  
  // The fruitDao.insert makes following
  Future insert(Fruit fruit) async {
    await _fruitStore.add(await _db, fruit.toJson());
  }
  </code></pre>
  
  <p>The JSON looks like that: {id: 1, name: Apple, isSweet: true, leaves: [Instance of 'Leaves', Instance of 'Leaves', Instance of 'Leaves']}</p>
  
  <p>The ERROR is following: 
  [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Invalid argument(s): value Instance of 'Leaves' unsupported type Leaves</p>