问题
Currently working on a little app that allows users to view a database stored on Heroku, however I am running into the aforementioned issue when using the database's URL: ".herokuapp.com/api/".
var client = createHttpClient();
var response = await client.read('<example>.herokuapp.com/api/<data>');
List data = JSON.decode(response);
Heroku doesn't seem to use HTTP(S) nor www, the latter of which I believe to be the issue.
Does anyone know how I can bypass or resolve this issue?
回答1:
I know this is an old problem but I just stumbled into this problem and fixed it by adding an "http://" before the URL.
回答2:
One of the problem is not having "http://" before your API URL;
SOLUTION Add "http://" before your API URL example API_URL = "api.openweathermap.org/data/2.5/weather?q={city%20name}&appid={your%20api%20key}"
By adding "http://" it becomes "http://api.openweathermap.org/data/2.5/weather?q={city%20name}&appid={your%20api%20key}"
回答3:
This is because the app tries to get renderUrl asynchronously. Before the render Url is fetched back, it is null. NetworkImage(renderUrl ?? '') then tries to use empty string as the url and result in the exception. I am not sure if this is the best solution, but this seems to work:
There are many ways to solve this, here is some of them
Add
https://
before your uriFor Image : I decided to check if the image url was empty before putting it in the widget:
CircleAvatar( backgroundColor: Colors.grey, backgroundImage: _urlImage.isNotEmpty ? NetworkImage(_urlImagem) : null, ),
回答4:
This works for me
child: CircleAvatar(
backgroundImage: _newImage
? FileImage(imageFile)
: imgUrl.isNotEmpty
? NetworkImage(imgUrl)
: null,),
来源:https://stackoverflow.com/questions/47957796/flutter-httpclient-invalid-arguments-no-host-specified-in-uri