title: Flutter - parse data from json is never completed
body: <p>I'm trying to retrieve from an API a list of data.<br />
  This is the response from the API:</p>
  <pre><code>{&quot;permission_requests&quot;:[{&quot;id&quot;:1,&quot;created_at&quot;:&quot;2020-11-02&quot;,&quot;reason&quot;:&quot;Aliquid cum autem id reprehenderit quam quis voluptate enim dolorem magnam doloremque et.&quot;,&quot;status&quot;:&quot;cancelled&quot;,&quot;date&quot;:&quot;06 Nov - 10 Nov&quot;,&quot;note&quot;:&quot;Odit a exercitationem iure culpa voluptatem.&quot;,&quot;is_pending&quot;:false,&quot;type_id&quot;:7},{&quot;id&quot;:5,&quot;created_at&quot;:&quot;2020-11-02&quot;,&quot;reason&quot;:&quot;Rerum incidunt explicabo accusantium nemo commodi quos sed et.&quot;,&quot;status&quot;:&quot;refused&quot;,&quot;date&quot;:&quot;13 Oct - 17 Oct&quot;,&quot;note&quot;:&quot;Corporis ad omnis animi.&quot;,&quot;is_pending&quot;:false,&quot;type_id&quot;:2},{&quot;id&quot;:11,&quot;created_at&quot;:&quot;2020-11-02&quot;,&quot;reason&quot;:&quot;Eveniet sed laudantium vitae perspiciatis molestiae sint minus dolores dolor numquam maxime facere deleniti velit.&quot;,&quot;status&quot;:&quot;cancelled&quot;,&quot;date&quot;:&quot;26 Sep&quot;,&quot;note&quot;:&quot;Debitis perferendis officia aliquam dolor recusandae.&quot;,&quot;is_pending&quot;:false,&quot;type_id&quot;:7},{&quot;id&quot;:14,&quot;created_at&quot;:&quot;2020-11-02&quot;,&quot;reason&quot;:&quot;Ut natus corporis necessitatibus et maiores accusamus repudiandae quas commodi consequatur ratione optio velit ducimus aut.&quot;,&quot;status&quot;:&quot;accepted&quot;,&quot;date&quot;:&quot;26 Sep&quot;,&quot;note&quot;:&quot;Unde possimus laudantium doloribus voluptate ullam.&quot;,&quot;is_pending&quot;:false,&quot;type_id&quot;:2},{&quot;id&quot;:17,&quot;created_at&quot;:&quot;2020-11-02&quot;,&quot;reason&quot;:&quot;Ut vel ea minus sint nemo et ex aut repellendus recusandae ex laboriosam sed aliquam veniam voluptas.&quot;,&quot;status&quot;:&quot;pending&quot;,&quot;date&quot;:&quot;26 Sep&quot;,&quot;note&quot;:&quot;Minima ullam itaque quae ex inventore voluptatum.&quot;,&quot;is_pending&quot;:true,&quot;type_id&quot;:4},{&quot;id&quot;:24,&quot;created_at&quot;:&quot;2020-11-02&quot;,&quot;reason&quot;:&quot;Rerum dignissimos est deserunt dolor aliquam qui repellat sequi quasi culpa rerum.&quot;,&quot;status&quot;:&quot;accepted&quot;,&quot;date&quot;:&quot;19 Sep - 2h&quot;,&quot;note&quot;:&quot;Architecto ab inventore id est.&quot;,&quot;is_pending&quot;:false,&quot;type_id&quot;:5},{&quot;id&quot;:29,&quot;created_at&quot;:&quot;2020-11-02&quot;,&quot;reason&quot;:&quot;Quas aspernatur impedit ea porro accusamus quas voluptatem magni temporibus velit error suscipit ab molestias in omnis.&quot;,&quot;status&quot;:&quot;refused&quot;,&quot;date&quot;:&quot;19 Sep - 2h&quot;,&quot;note&quot;:&quot;Sunt beatae sit quia voluptates et enim cumque ut.&quot;,&quot;is_pending&quot;:false,&quot;type_id&quot;:5}]}
  </code></pre>
  <p>And this is my code:</p>
  <pre><code>import 'dart:convert';
  
  import 'package:dio/dio.dart';
  import 'package:richiesta_permessi/const.dart';
  import 'package:shared_preferences/shared_preferences.dart';
  
  import 'package:richiesta_permessi/exceptions/exceptions.dart';
  import 'package:richiesta_permessi/models/permission_request.dart';
  import 'package:richiesta_permessi/repositories/authentication.dart';
  
  abstract class PermissionRequestsRepository {
    Future&lt;List&lt;PermissionRequestModel&gt;&gt; getPermissionRequests();
    Future&lt;bool&gt; sendCancelRequest(String permissionRequestId);
  }
  
  class RestPermissionRequestsRepository extends PermissionRequestsRepository {
    List&lt;PermissionRequestModel&gt; permissionRequests;
    var httpClient = new Dio();
  
    @override
    Future&lt;List&lt;PermissionRequestModel&gt;&gt; getPermissionRequests() async {
      try {
        Future&lt;SharedPreferences&gt; _prefs = SharedPreferences.getInstance();
        final SharedPreferences prefs = await _prefs;
        String token = prefs.getString('user_token') ?? null;
  
        if (null == token) {
          throw PermissionRequestsException(
            message: 'Non è stato possibile recuperare la lista delle richieste',
          );
        }
  
        httpClient.options.headers['content-Type'] = 'application/json';
        httpClient.options.headers['Authorization'] = 'Bearer $token';
        Response response = await httpClient.get(kGetPermissionRequestsUrl);
  
        if (response.statusCode != 200) {
          throw PermissionRequestsException(
            message: 'Non è stato possibile recuperare la lista delle richieste',
          );
        }
  
        final permissionList = response.data['permission_requests'];
  
        final List&lt;PermissionRequestModel&gt; permissionRequests = permissionList.map((value) =&gt; PermissionRequestModel.fromJson(value)).toList();
  
  print('The list is done');
            
        return permissionRequests;
      } catch (e) {
        throw PermissionRequestsException(
          message: 'Non è stato possibile recuperare la lista delle richieste',
        );
      }
    }
  
    @override
    Future&lt;bool&gt; sendCancelRequest(String permissionRequestId) async {
      try {
        await Future.delayed(Duration(seconds: 1));
        return true;
      } catch (e) {
        throw PermissionRequestsException(
          message: 'Non è stato possibile annullare la richiesta',
        );
      }
    }
  }
  </code></pre>
  <p>This is the PermissionRequestModel:</p>
  <pre><code>import 'package:meta/meta.dart';
  
  class PermissionRequestModel {
    final String id;
    final String reason;
    final String status;
    final String note;
    final String date;
    final bool isPending;
  
    PermissionRequestModel({
      @required this.id,
      @required this.reason,
      @required this.status,
      @required this.note,
      @required this.date,
      @required this.isPending,
    });
  
    factory PermissionRequestModel.fromJson(Map&lt;String, dynamic&gt; json) {
      return PermissionRequestModel(
        id: json['id'].toString(),
        reason: json['reason'],
        status: json['status'],
        note: json['note'],
        date: json['date'],
        isPending: json['is_pending'],
      );
    }
  }
  </code></pre>
  <p>The app has a BloC that call the repository and the request is correctly made, it call the API and retrieve the data.<br />
  The data is stored in the variable but seems that the <code>fromJson</code> is never completed, I have tried to print the <code>value</code> and it pass only once, can't figured out why.</p>
  <p>Can't understand where the problem is, the <code>print('The list is done');</code>is neve reached.</p>
  <p>EDIT:<br />
  I have changed the code, now I have added a simple for loop:</p>
  <pre><code>List&lt;PermissionRequestModel&gt; permissionRequests;
  for (int i = 0; i &lt; permissionList.length; i++) {
          permissionRequests.add(PermissionRequestModel.fromJson(permissionList[i]));
  }
  </code></pre>
  <p>even with this code it do not return anything, if I manually add the data with this, it works:</p>
  <pre><code>permissionRequests = [
          PermissionRequestModel(
            id: '1',
            reason: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
            status: 'cancelled',
            note: 'Nulla facilisi. Donec mi risus, fringilla a felis ut, auctor placerat leo. Vivamus non placerat eros. Donec quis ullamcorper velit. Vestibulum nec ante efficitur, elementum urna et, feugiat est. Maecenas vel cursus nulla.',
            date: '20 ottobre',
          ),
          PermissionRequestModel(
            id: '2',
            reason: 'In in eros non sapien tempor egestas at nec tellus',
            status: 'refused',
            note: 'Nulla facilisi. Donec mi risus, fringilla a felis ut, auctor placerat leo. Vivamus non placerat eros. Donec quis ullamcorper velit. Vestibulum nec ante efficitur, elementum urna et, feugiat est. Maecenas vel cursus nulla.',
            date: 'Dal 20 al 22 ottobre',
          ),
          PermissionRequestModel(
            id: '3',
            reason: 'Nam ut condimentum dui. Nulla sed ultrices lacus. egestas at nec tellus',
            status: 'pending',
            note: 'Nulla facilisi. Donec mi risus, fringilla a felis ut, auctor placerat leo. Vivamus non placerat eros. Donec quis ullamcorper velit. Vestibulum nec ante efficitur, elementum urna et, feugiat est. Maecenas vel cursus nulla.',
            date: '20 ottobre - 3 ore',
          ),
        ];
  </code></pre>
  <p>How is this possibile? Whats the difference?</p>
  <p>EDIT 2:
  ok the problem is the <code>permissionRequests</code> when I try to use <code>.add</code>, for some reason it just try to parse the first element and then it runs forever</p>