title: Convert Future<int> to int in Flutter
body: <p>My goal is to sort a list of racks compared to the geo position of the user. Here's my code:</p>
  
  <pre><code>import 'package:geolocator/geolocator.dart';
  import 'rack.dart';
  import 'dart:async';
  class RackList {
  
    List&lt;Rack&gt; _racks;
    RackList(this._racks);
    get racks =&gt; _racks;
  
    factory RackList.fromJson(Map&lt;String,dynamic&gt; json){
      var list = json['racks'] as List;
  
      Future&lt;int&gt; calculateDistance(var element) async{
        var startLatitude=45.532;
        var startLongitude=9.12246;
        var endLatitude=element.latitude;
        var endLongitude=element.longitude;
        var dist = await Geolocator().distanceBetween(
            startLatitude,
            startLongitude,
            endLatitude,
            endLongitude);
        var distance=(dist/1000).round();
        return distance;
      }
  
      list = list.map((i) =&gt; Rack.fromJson(i)).toList();
  
        for (int i = 0; i &lt; list.length; i++) {
          var dist =  calculateDistance(list[i]);
          print(dist); //prints Instance of 'Future&lt;int&gt;'
          list[i].distance=dist; //crash
      }
  
      list.sort((a, b) =&gt; a.distance.compareTo(b.distance));
      return RackList(list);
    }
  }
  </code></pre>
  
  <p>The problem is in the for cycle, the variable <code>dist</code> is a <code>Future&lt;int&gt;</code> type and cannot be assigned to <code>list[i].distance</code>. How can I convert that value to a normal int?</p>
  
  <p>I've tried the solution of @Nuts but:</p>
  
  <pre><code>var distances = new List();
  for (int i = 0; i &lt; list.length; i++) {
        calculateDistance(list[i]).then((dist) {
          distances.add(dist);
          print(distances[i]); //print the correct distance
        });
      }
  print("index 0 "+distances[0].toString()); //prints nothing
  </code></pre>
  
  <p>It's like outside the for-cycle I lost all the values inside the <code>distances</code> list</p>