http.get(url) in flutter not accepting string value. It says string value cant be assigned to uri type

Viewed 1533

I am new to flutter but few days ago http.get(url) where url as string was being accepted but now its not working. It says string value cant be assigned to URI

Future getNews() async{
  var client = http.Client();
  var response = await client.get('http://newsapi.org/v2/everything?q=tesla&from=2021-02-17&sortBy=publishedAt&apiKey=230538c0a3f2450ba9ddf5802220ccf9');
}
1 Answers

You can read in the documentation of Flutter here you can't give a string to the get method.

Like you said you need to use Uri.

return http.get(Uri.https('your_url'), headers_if_you_need);

You can also use Uri.parse like this

return http.get(Uri.parse('your_url'));
Related