title: How to get List from api in flutter
body: <p>I'm Trying to get a list of users from my api through ApiService and model it in my UserModel class.
  It's giving me this error <code>The argument type 'List&lt;Result&gt;?' can't be assigned to the parameter type 'List&lt;Result&gt;'</code>.</p>
  <p>The results are also not showing on the screen.</p>
  <p>Much obliged</p>
  <p>If the provided code is not enough and you want to take a look at the full project, here's the repo:
  <a href="https://github.com/renslakens/SkoolWorkshopApp.git" rel="nofollow noreferrer">https://github.com/renslakens/SkoolWorkshopApp.git</a></p>
  <p><strong>UserModel class</strong></p>
  <pre class="lang-dart prettyprint-override"><code>// To parse this JSON data, do
  //
  //     final welcome = welcomeFromJson(jsonString);
  
  import 'dart:convert';
  
  class UserModel {
    UserModel({
      required this.status,
      required this.result,
    });
  
    int status;
    List&lt;Result&gt; result;
  
    factory UserModel.fromJson(Map&lt;String, dynamic&gt; json) =&gt;
        UserModel(
          status: json[&quot;status&quot;] == null ? null : json[&quot;status&quot;],
          result: json[&quot;result&quot;] == null ? null : List&lt;Result&gt;.from(
              json[&quot;result&quot;].map((x) =&gt; Result.fromJson(x))),
        );
  
    Map&lt;String, dynamic&gt; toJson() =&gt;
        {
          &quot;status&quot;: status == null ? null : status,
          &quot;result&quot;: result == null ? null : List&lt;dynamic&gt;.from(result.map((x) =&gt; x.toJson())),
        };
  }
  
  class Result {
    
    Result userModelFromJson(String str) =&gt; Result.fromJson(json.decode(str));
    String userModelToJson(UserModel data) =&gt; json.encode(data.toJson());
    
    Result({
      required this.docentId,
      required this.naam,
      required this.achternaam,
      required this.emailadres,
      required this.geboortedatum,
      required this.geboorteplaats,
      this.maxRijafstand,
      this.heeftRijbewijs,
      this.heeftAuto,
      required this.straat,
      required this.huisnummer,
      required this.geslacht,
      required this.nationaliteit,
      required this.woonplaats,
      required this.postcode,
      required this.land,
      required this.wachtwoord,
      required this.isAccepted,
      this.isFlexwerker,
    });
  
    int docentId;
    String naam;
    String achternaam;
    String emailadres;
    String geboortedatum;
    String geboorteplaats;
    dynamic maxRijafstand;
    dynamic heeftRijbewijs;
    dynamic heeftAuto;
    String straat;
    int huisnummer;
    String geslacht;
    String nationaliteit;
    String woonplaats;
    String postcode;
    String land;
    String wachtwoord;
    int isAccepted;
    dynamic isFlexwerker;
  
    factory Result.fromJson(Map&lt;String, dynamic&gt; json) =&gt;
        Result(
          docentId: json[&quot;docentID&quot;] == null ? null : json[&quot;docentID&quot;],
          naam: json[&quot;naam&quot;] == null ? null : json[&quot;naam&quot;],
          achternaam: json[&quot;achternaam&quot;] == null ? null : json[&quot;achternaam&quot;],
          emailadres: json[&quot;emailadres&quot;] == null ? null : json[&quot;emailadres&quot;],
          geboortedatum: json[&quot;geboortedatum&quot;] == null ? null : (json[&quot;geboortedatum&quot;]),
          geboorteplaats: json[&quot;geboorteplaats&quot;] == null
              ? null
              : json[&quot;geboorteplaats&quot;],
          maxRijafstand: json[&quot;maxRijafstand&quot;],
          heeftRijbewijs: json[&quot;heeftRijbewijs&quot;],
          heeftAuto: json[&quot;heeftAuto&quot;],
          straat: json[&quot;straat&quot;] == null ? null : json[&quot;straat&quot;],
          huisnummer: json[&quot;huisnummer&quot;] == null ? null : json[&quot;huisnummer&quot;],
          geslacht: json[&quot;geslacht&quot;] == null ? null : json[&quot;geslacht&quot;],
          nationaliteit: json[&quot;nationaliteit&quot;] == null
              ? null
              : json[&quot;nationaliteit&quot;],
          woonplaats: json[&quot;woonplaats&quot;] == null ? null : json[&quot;woonplaats&quot;],
          postcode: json[&quot;postcode&quot;] == null ? null : json[&quot;postcode&quot;],
          land: json[&quot;land&quot;] == null ? null : json[&quot;land&quot;],
          wachtwoord: json[&quot;wachtwoord&quot;] == null ? null : json[&quot;wachtwoord&quot;],
          isAccepted: json[&quot;isAccepted&quot;] == null ? null : json[&quot;isAccepted&quot;],
          isFlexwerker: json[&quot;isFlexwerker&quot;],
        );
  
    Map&lt;String, dynamic&gt; toJson() =&gt;
        {
          &quot;docentID&quot;: docentId == null ? null : docentId,
          &quot;naam&quot;: naam == null ? null : naam,
          &quot;achternaam&quot;: achternaam == null ? null : achternaam,
          &quot;emailadres&quot;: emailadres == null ? null : emailadres,
          &quot;geboortedatum&quot;: geboortedatum == null ? null : geboortedatum,
          &quot;geboorteplaats&quot;: geboorteplaats == null ? null : geboorteplaats,
          &quot;maxRijafstand&quot;: maxRijafstand,
          &quot;heeftRijbewijs&quot;: heeftRijbewijs,
          &quot;heeftAuto&quot;: heeftAuto,
          &quot;straat&quot;: straat == null ? null : straat,
          &quot;huisnummer&quot;: huisnummer == null ? null : huisnummer,
          &quot;geslacht&quot;: geslacht == null ? null : geslacht,
          &quot;nationaliteit&quot;: nationaliteit == null ? null : nationaliteit,
          &quot;woonplaats&quot;: woonplaats == null ? null : woonplaats,
          &quot;postcode&quot;: postcode == null ? null : postcode,
          &quot;land&quot;: land == null ? null : land,
          &quot;wachtwoord&quot;: wachtwoord == null ? null : wachtwoord,
          &quot;isAccepted&quot;: isAccepted == null ? null : isAccepted,
          &quot;isFlexwerker&quot;: isFlexwerker,
        };
  }
  </code></pre>
  <p><strong>APIService class</strong></p>
  <pre class="lang-dart prettyprint-override"><code>class ApiService {
    Future&lt;List&lt;UserModel&gt;&gt; getUsers() async {
      try {
        var url = Uri.parse(apis.baseUrl + apis.getUsers);
        var response = await http.get(url);
        if (response.statusCode == 200) {
          List&lt;UserModel&gt; model = userModelFromJson(response.body);
          return model;
        }
      } catch (e) {
        log(e.toString());
      }
    }
  }
  </code></pre>
  <p><strong>Results from the API to list all the imported users</strong></p>
  <pre class="lang-json prettyprint-override"><code>{
      &quot;status&quot;: 200,
      &quot;result&quot;: [
          {
              &quot;docentID&quot;: 1,
              &quot;naam&quot;: &quot;gerrit&quot;,
              &quot;achternaam&quot;: &quot;petersen&quot;,
              &quot;emailadres&quot;: &quot;meel@meel.com&quot;,
              &quot;geboortedatum&quot;: &quot;1899-11-29T23:40:28.000Z&quot;,
              &quot;geboorteplaats&quot;: &quot;&quot;,
              &quot;maxRijafstand&quot;: null,
              &quot;heeftRijbewijs&quot;: null,
              &quot;heeftAuto&quot;: null,
              &quot;straat&quot;: &quot;&quot;,
              &quot;huisnummer&quot;: 0,
              &quot;geslacht&quot;: &quot;&quot;,
              &quot;nationaliteit&quot;: &quot;&quot;,
              &quot;woonplaats&quot;: &quot;&quot;,
              &quot;postcode&quot;: &quot;&quot;,
              &quot;land&quot;: &quot;&quot;,
              &quot;wachtwoord&quot;: &quot;$2b$10$kcVpe9yOdKzMPdEUcMIATOh3PE42GDiQfDLZeufKxpLpTb51Af7Ay&quot;,
              &quot;isAccepted&quot;: 0,
              &quot;isFlexwerker&quot;: null
          },
          {
              &quot;docentID&quot;: 4,
              &quot;naam&quot;: &quot;gerrit&quot;,
              &quot;achternaam&quot;: &quot;petersen&quot;,
              &quot;emailadres&quot;: &quot;123mail123@meel.com&quot;,
              &quot;geboortedatum&quot;: &quot;1899-11-29T23:40:28.000Z&quot;,
              &quot;geboorteplaats&quot;: &quot;&quot;,
              &quot;maxRijafstand&quot;: null,
              &quot;heeftRijbewijs&quot;: null,
              &quot;heeftAuto&quot;: null,
              &quot;straat&quot;: &quot;&quot;,
              &quot;huisnummer&quot;: 0,
              &quot;geslacht&quot;: &quot;&quot;,
              &quot;nationaliteit&quot;: &quot;&quot;,
              &quot;woonplaats&quot;: &quot;&quot;,
              &quot;postcode&quot;: &quot;&quot;,
              &quot;land&quot;: &quot;&quot;,
              &quot;wachtwoord&quot;: &quot;$2b$10$jNx8CrBRw78VZdoTTomGWuVF4CEa6wcMMsIzmkHak1WjRVsfHaX86&quot;,
              &quot;isAccepted&quot;: 0,
              &quot;isFlexwerker&quot;: null
          },
          {
              &quot;docentID&quot;: 7,
              &quot;naam&quot;: &quot;Peter&quot;,
              &quot;achternaam&quot;: &quot;gerritsen&quot;,
              &quot;emailadres&quot;: &quot;test1@meel.com&quot;,
              &quot;geboortedatum&quot;: &quot;1899-11-29T23:40:28.000Z&quot;,
              &quot;geboorteplaats&quot;: &quot;&quot;,
              &quot;maxRijafstand&quot;: null,
              &quot;heeftRijbewijs&quot;: null,
              &quot;heeftAuto&quot;: null,
              &quot;straat&quot;: &quot;&quot;,
              &quot;huisnummer&quot;: 0,
              &quot;geslacht&quot;: &quot;&quot;,
              &quot;nationaliteit&quot;: &quot;&quot;,
              &quot;woonplaats&quot;: &quot;&quot;,
              &quot;postcode&quot;: &quot;&quot;,
              &quot;land&quot;: &quot;&quot;,
              &quot;wachtwoord&quot;: &quot;$2b$10$JRbNe40U7Fk2hcA4B4bgEe9ElmCX5dCovf5FNtZTLHLCX8v/DeiN2&quot;,
              &quot;isAccepted&quot;: 0,
              &quot;isFlexwerker&quot;: null
          }
      ]
  }
  </code></pre>