title: How to create List of object after parsing json in dart
body: <p>This is how I am parsing my JSON, It's working but I want to know how would I create an instance of <code>List&lt;Result&gt;</code> to access the data inside it in my widgets. Help, please!</p>
  <pre><code>class Test {
    Test({
      required this.results,
    });
  
    List&lt;Result&gt; results;
  
    factory Test.fromJson(Map&lt;String, dynamic&gt; json) =&gt; Test(
          results:
              (json[&quot;results&quot;] as List).map((e) =&gt; Result.fromJson(e)).toList(),
        );
  }
  
  Test testFromJson(String str) =&gt; Test.fromJson(json.decode(str));
  </code></pre>
  <p>Secondly, when I use this code in the section below instead of the last line of code in the above section, I get the following type error, please tell me what exactly this error means.</p>
  <blockquote>
  <p>_TypeError (type '(dynamic) =&gt; Test' is not a subtype of type '(String, dynamic) =&gt; MapEntry&lt;dynamic, dynamic&gt;' of 'transform')</p>
  </blockquote>
  <pre><code>List&lt;Test&gt; modelFromJson(String str) =&gt;
  List&lt;Test&gt;.from(json.decode(str).map((x) =&gt; Test.fromJson(x)));
  </code></pre>