Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

flutter - 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"
    });
Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To improve compile-time type safety, package:http 0.13.0 introduced breaking changes that made all functions that previously accepted Uris or Strings now accept only Uris instead. You will need to explicitly use Uri.parse to create Uris from Strings. (package:http formerly called that internally for you.)

Old Code Replace With
http.get(someString) http.get(Uri.parse(someString))
http.post(someString) http.post(Uri.parse(someString))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...