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?
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 uri
For 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,
),
I know this is an old problem but I just stumbled into this problem and fixed it by adding an "http://"
before the URL.
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}"
If you still get this issue in latest versions of flutter, try to check the following things.
Previously uri was in String type. Now its in Uri type for the http requests.
If we try to use the url as
String urlPath = '<example>.herokuapp.com/api/<data>';
client.read(Uri(path: urlPath));
We will get the exception as No host specified in URI
This can be solved by using parse method in Uri class
client.read(Uri.parse(urlPath));
It solves the issue.
This works for me
child: CircleAvatar(
backgroundImage: imageFile != null
? FileImage(imageFile)
: imgUrl.isNotEmpty
? NetworkImage(imgUrl)
: null,),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With