3

I store the API error logs in my DB. I found so many errors on my DB. the log message is the same.

SocketException: Failed host lookup: 'xxx.abc.com' (OS Error: No address associated with hostname, errno = 7), StackTrace : 

BTW, This error only occurs to random users. Not for all users.

function

  Future<dynamic> abc() async {
    var responseJson;
    try {
      final response = await http.post('${env.url}/xxx/xxx/xxx', headers: {'Authorization': 'Bearer xxx'});
      responseJson = _response(response, _errorMap);
      return responseJson;
    }
    catch (e, s) {
      errorLog.store('$e, StackTrace : $s', _errorMap);
      throw FetchDataException('message');
    }
  }

env.url looks like this, https://xxx.abc.com

xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="xxx">
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.VIBRATE"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <application ...

package

  http: ^0.12.2
BIS Tech
  • 17,000
  • 12
  • 99
  • 148

5 Answers5

3

Make Sure that you have active internet connection along with permission defined in AndroidManifest.xml

Kalpesh Khandla
  • 758
  • 1
  • 9
  • 22
2

This may not be a Flutter problem. Instead, that is OS Error which is far more low level.

Firstly, have a check at this: Unable to resolve host "<url here>"; No address associated with hostname.

For example, if your user closed his Wifi and mobile network, then you will see this error.

Usually it is not caused by a bug in your code, but just because the user has no network - if he has no network, how can he resolve the domain name!

Thus, for me, personally, I just ignore such type of error. In other words, I do not report these errors to my backend.

ch271828n
  • 15,854
  • 5
  • 53
  • 88
  • Thanks. okay, but how this log message store on DB without the internet? btw, I used firestore – BIS Tech Jan 15 '21 at 05:22
  • @BloodLoss temporarily save on local file. then upload when have network. for example, https://flutter.dev/docs/cookbook/persistence/reading-writing-files – ch271828n Jan 15 '21 at 14:40
1

In my case, I restarted my laptop and it was fine. Most of the times restarting computer will solve the problems like this.

atigdawgahb
  • 41
  • 1
  • 5
1
  1. First thing we should have a active internet connection.

  2. Second thing we should enable the wifi in our android emulator.

  3. Next thing we should add permissions correctly in AndroidManifest.xml

[Flutter Networking] : https://docs.flutter.dev/development/data-and-backend/networking

<manifest xmlns:android...>
 ...
 <uses-permission android:name="android.permission.INTERNET" />
 <application ...
</manifest>
  1. Then after we do those steps we should restart the emulator and run the app.
Jack Y
  • 75
  • 7
0

In My case I opened the emulator and after that I connected to the WIFI. So, wifi connected to my system but unable to connect to emulator .

Solutions:

  • I Closed the emulator and re-open it. And Finally works..
Rahul Kushwaha
  • 5,473
  • 3
  • 26
  • 30