1

On the new version of the dart http module for flutter I have a problem indeed I want to use an API with the get method by passing arguments

'http://host.com?data1=1&data2=2' ...

And since the new version we have to put the url this way

http.get(
   Uri.http ('host.com', '/'),
)

or I don't know how to pass the data

4 Answers 4

2

Use the query parameters parameter of the Uri.http constructor.

Uri.http ('host.com', '/', {
  'data1': '1',
  'data2': '2',
  ...
})
Sign up to request clarification or add additional context in comments.

Comments

1

You have to put it in the form

Uri.http ('host.com', '/',parameters),

Inside parameters you have to put a Map like

Map<String, String> parameters = { "data1" : "1" }

And if you are using http dont forget to put

    <application android:usesCleartextTraffic="true"/>

inside your AndroidManifest.xml because otherwise you get the next error :) .

Comments

0

For url parameters, you can try just:

String url = 'http://host.com';
url += '?data1=1';

var response = await http.get(url);

Comments

0

You can simply wrap your old url String with Uri.parse.

http.get(Uri.parse('http://host.com?data1=1&data2=2'));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.