title: Parsing a List in Flutter / Dart
body: <p>I've a list that looks like this: </p>
  
  <pre><code>[{id: 1, user_id: 3, challenge_id: 1, created_at: 2019-06-09 06:36:39, image_caption: Enter your image caption here, image_path: https://res.cloudinary.com/dqrmgdpcf/image/upload/v1560062199/zex61jegvqwkevq6qrmd.jpg, image: null, user_upvoted: null, user_downvoted: null, score: 0}, {id: 2, user_id: 2, challenge_id: 1, created_at: 2019-06-12 09:17:07, image_caption: , image_path: https://res.cloudinary.com/dqrmgdpcf/image/upload/v1560331027/dj94sjzufx8gznyxrves.jpg, image: null, user_upvoted: null, user_downvoted: null, score: 0}, 
  {id: 2, user_id: 3, challenge_id: 1, created_at: 2019-06-09 06:36:39, image_caption: Enter your image caption here, image_path: https://res.cloudinary.com/dqrmgdpcf/image/upload/v1560062199/zex61jegvqwkevq6qrmd.jpg, image: null, user_upvoted: null, user_downvoted: null, score: 0}, {id: 2, user_id: 2, challenge_id: 1, created_at: 2019-06-12 09:17:07, image_caption: , image_path: https://res.cloudinary.com/dqrmgdpcf/image/upload/v1560331027/dj94sjzufx8gznyxrves.jpg, image: null, user_upvoted: null, user_downvoted: null, score: 0}, 
  {id: 3, user_id: 3, challenge_id: 1, created_at: 2019-06-09 06:36:39, image_caption: Enter your image caption here, image_path: https://res.cloudinary.com/dqrmgdpcf/image/upload/v1560062199/zex61jegvqwkevq6qrmd.jpg, image: null, user_upvoted: null, user_downvoted: null, score: 0}, {id: 2, user_id: 2, challenge_id: 1, created_at: 2019-06-12 09:17:07, image_caption: , image_path: https://res.cloudinary.com/dqrmgdpcf/image/upload/v1560331027/dj94sjzufx8gznyxrves.jpg, image: null, user_upvoted: null, user_downvoted: null, score: 0}]
  </code></pre>
  
  <p>So it's basically 3 objects. </p>
  
  <p>The object model looks like this: </p>
  
  <pre><code>class ChallengeUpload {
    int id = 0;
    int userId = 0;
    int challengeId = 0;
    String createdAt = "";
    String imageCaption = "";
    String imagePath = "";
    File image;
    String userUpvoted = "";
    String userDownvoted = "";
    int score = 0;
  
    ChallengeUpload();
  
    ChallengeUpload.fromJson(Map&lt;String, dynamic&gt; json) {
      id = json['id'];
      userId = json['user_id'];
      challengeId = json['challenge_id'];
      createdAt = json['created_at'];
      imageCaption = json['image_caption'];
      imagePath = json['image_path'];
      userUpvoted = json['user_upvoted'];
      userDownvoted = json['user_downvoted'];
      score = json['score'];
    }
  
    Map&lt;String, dynamic&gt; toJson() {
      final Map&lt;String, dynamic&gt; data = new Map&lt;String, dynamic&gt;();
      data['id'] = this.id;
      data['user_id'] = this.userId;
      data['challenge_id'] = this.challengeId;
      data['created_at'] = this.createdAt;
      data['image_caption'] = this.imageCaption;
      data['image_path'] = this.imagePath;
      data['user_upvoted'] = this.userUpvoted;
      data['user_downvoted'] = this.userDownvoted;
      data['score'] = this.score;
      return data;
    }
  }
  </code></pre>
  
  <p>I can't seem to figure out how to parse this list. </p>
  
  <p>If it's just a single object that's being returned by my API I run it through this function: </p>
  
  <p><code>currentChallenge = Challenge.fromJson(response.data);</code></p>
  
  <p>How to do something similar but then end up with a UploadedChallengesList instead of a single object?</p>
  
  <p>I've tried: </p>
  
  <p><code>challengeUploads = json.decode(response.data).map&lt;ChallengeUpload&gt;((dynamic challengeUpload) =&gt; ChallengeUpload.fromJson(challengeUpload)).toList();</code></p>
  
  <p>It'll print: 
  <code>I/flutter ( 2660): type 'List&lt;dynamic&gt;' is not a subtype of type 'String'</code></p>
  
  <p>My JSON: </p>
  
  <pre><code>{  
     id:1,
     user_id:3,
     challenge_id:1,
     created_at:2019-06   -09   06:36:39,
     image_caption:Enter your image caption here,
     image_path:   https://res.cloudinary.com/dqrmgdpcf/image/upload/v1560062199/zex61jegvqwkevq6qrmd.jpg,
     image:null,
     user_upvoted:null,
     user_downvoted:null,
     score:0
  },
  {  
     id:2,
     user_id:2,
     challenge_id:1,
     created_at:2019-06   -12   09:17:07,
     image_caption:,
     image_path:   https://res.cloudinary.com/dqrmgdpcf/image/upload/v1560331027/dj94sjzufx8gznyxrves.jpg,
     image:null,
     user_upvoted:null,
     user_downvoted:null,
     score:0
  }
  </code></pre>
  
  <p>Edit: I found out it had to do with the library I'm using to do API calls. I use Dio and my code ended up looking like this:</p>
  
  <pre><code>  Response response = await Dio().get(url,
        options: Options(
            headers: {"Authorization": accessToken},
            responseType: ResponseType.json));
  
    setState(() {
      challengeUploads = response.data
          .map&lt;ChallengeUpload&gt;((dynamic challengeUpload) =&gt;
              ChallengeUpload.fromJson(challengeUpload))
          .toList();
    });
  </code></pre>