Home > Back-end >  The argument type 'String' can't be assigned to the parameter type 'int'
The argument type 'String' can't be assigned to the parameter type 'int'

Time:09-30

i want get the data from:

class Data {
  List allstores = [
    {
      "id": "110000",
      "lat": -6.175392,
      "lng": 106.827153,
      "distance": 0,
    },
  ];
}

and then i call it on a function that count the distance of two latitude:

Future _getTheDistance() async {

    for (int i = 0; i < data.allstores.length; i  ) {
      double storelat = data.allstores[i]['lat'];
      double storelng = data.allstores[i]['lng'];

      distanceImMeter = await Geolocator.distanceBetween(
        _currentPosition!.latitude,
        _currentPosition!.longitude,
        storelat,
        storelng,
      );
      var distance = distanceImMeter?.round().toInt();

      data.allstores[i]['distance'] = (distance! / 100);
      setState(() {});
    }
  }

when i call the data that i store on class Data to user interface:

Text( "${data.allstores['distance'].round()} KM Away",),

it shows the alert just like this:

The argument type 'String' can't be assigned to the parameter type 'int'.

does anyone know how to get the data that i store?

CodePudding user response:

If I'm not mistaken you are storing data as ArrayList<HashMap<Int,String>> You are trying to retrieve an element of the array incorrectly. You need to redefine the retrieved data

CodePudding user response:

You have defined allStores as an array , so while you are going to access any value from array give an array position from which index you want to get value, use this :

Text( "${data.allstores[0]['distance'].round()} KM Away",),

The argument type 'String' can't be assigned to the parameter type 'int' gives because you've not given array index

  • Related