27

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?

Oscar Cooke-Abbott
  • 463
  • 1
  • 6
  • 13

9 Answers9

56

I know this is an old problem but I just stumbled into this problem and fixed it by adding an "http://" before the URL.

Ravindra S. Patil
  • 11,757
  • 3
  • 13
  • 40
Rodrigo Ortega
  • 706
  • 7
  • 9
15

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}"

eclat_soft
  • 602
  • 7
  • 9
8

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.

Sankar Arumugam
  • 321
  • 4
  • 3
4

This works for me

child: CircleAvatar(
      backgroundImage: imageFile != null
          ? FileImage(imageFile)
          : imgUrl.isNotEmpty
              ? NetworkImage(imgUrl)
              : null,),
Kaushal Kishore
  • 447
  • 1
  • 5
  • 13
Hamdam Muqimov
  • 319
  • 2
  • 7
2

This has worked for me

CachedNetworkImage(imageUrl:  'https://example.com/'+item['image'],),
MendelG
  • 14,885
  • 4
  • 25
  • 52
  • 1
    How is this different from the earlier answers that not only show the same solution but also explain it, and also more directly relate to the original question? – user643011 May 05 '22 at 22:56
1

Just add http:// before your url

From :

 192.168.2.101/test/login

To :

 http://192.168.2.101/test/login
Anand
  • 4,355
  • 2
  • 35
  • 45
0

You should always specify a Default Value of the Image Path if you are displaying the image on the same page try adding this to your widget:

  child: Image.network(
     valueOrDefault<String>(                                              
      listViewDocumentsRecord.docImageUrl,                                             
      'https://picsum.photos/seed/513/600',
       ),
            
0

You need to breakdown the URL as per the uri sytax to the following:

For normal non-secured URLs:

final httpUri = Uri(
    scheme: 'http',
    host: 'dart.dev',
    path: 'guides/libraries/library-tour',
    fragment: 'numbers');
print(httpUri); // http://dart.dev/guides/libraries/library-tour#numbers

For secured URLs:

final httpsUri = Uri(
    scheme: 'https',
    host: 'dart.dev',
    path: 'guides/libraries/library-tour',
    fragment: 'numbers');
print(httpsUri); // https://dart.dev/guides/libraries/library-tour#numbers

For email URLs use the following:

final mailtoUri = Uri(
    scheme: 'mailto',
    path: 'John.Doe@example.com',
    queryParameters: {'subject': 'Example'});
print(mailtoUri); // mailto:John.Doe@example.com?subject=Example