romajc
romajc

Reputation: 19

How to use a double value from an api in Flutter?

I feel kinda dumb asking this. Because I was able to parse Maps and Lists from the api but I have no idea how to use something as simple as a double from the same api.

I simply want to make a

double yld;

from this api link,

https://sandbox.iexapis.com/stable/data-points/market/DGS10?token=Tsk_38ddda0b877a4510b42a37ae713cdc96

Upvotes: 0

Views: 601

Answers (1)

JideGuru
JideGuru

Reputation: 7670

The response body is a String so you'll have to parse it into a double using double.parse()

getYld() async {
  var url = 'https://sandbox.iexapis.com/stable/data-points/market/DGS10? 
  token=Tsk_38ddda0b877a4510b42a37ae713cdc96';
  var res = await http.get(url);
  if (res.statusCode == 200) {
     double yld = double.parse(res.body);  // parse the double here
  }
}

Upvotes: 1

Related Questions