Unhandled Exception: SocketException: OS Error: Connection refused
Jul 31, 2021
Issue : Following is an error received when connecting PostgreSQL and Flutter. The error occurs when trying to connect through the android emulator in a development environment.
E/flutter ( 8084): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: SocketException: OS Error: Connection refused, errno = 111, address = localhost, port = 43992
Solution :
- Make sure you have given internet permission in your app’s by adding the following lines in the android/app/src/main/AndroidManifest.xml file
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
2. Replace localhost with 10.0.2.2 or 10.1.1.1(for android emulator)