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

I am trying to make an HTTP POST request with the flutter plugin HTTP but I am getting an error of the title. Does anyone know the cause of this since in my other applications this works just perfectly fine?

await http.post(Uri.encodeFull("https://api.instagram.com/oauth/access_token"), body: {
      "client_id": clientID,
      "redirect_uri": redirectUri,
      "client_secret": appSecret,
      "code": authorizationCode,
      "grant_type": "authorization_code"
    });


Solution 1:[1]

String url ='example.com';

http.get(Uri.parse(url),

);

Solution 2:[2]

You need to parse your URL By using the Uri.parse() method, you can create a new Uri object by parsing a URI string.

import 'package:http/http.dart' as http;

void getData() async {
    try {
      final String apiEndpoint =
          'https://api.instagram.com/oauth/access_token';
      final Uri url = Uri.parse(apiEndpoint);
      final response = await http.post(url);
      print(response);
    } catch (err) {
      print(err);
    }
}

more brief explanation, What am doing here is parsing the JSON from URL. So in the await http.get(uri) method the uri is the String variable which holds server URL. So to solve this error all we have to do is Wrap the uri or the URL into Uri.parse() method

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TuGordoBello
Solution 2 Paresh Mangukiya