Reputation: 15
I am not able to load the image in my flutter app it gives the error Exception caught by image resource service The following HttpException was thrown resolving an image codec:
Connection closed while receiving data
The image section is completely blank in the flutter app.
Below is my code:
API code:
class ApiClient extends GetConnect implements GetxService {
late String token;
final String appBaseurl;
late Map<String, String> _mainHeaders;
ApiClient({required this.appBaseurl}) {
baseUrl = appBaseurl;
timeout = Duration(seconds: 30);
token = AppConstants.TOKEN;
_mainHeaders = {
"Content-type": "application/json; charset=UTF-8",
"Authorization": "Bearer $token",
'Accept-Encoding': 'gzip, deflate, br',
};
}`
Future<Response> getData(String uri) async {
try {
Response response = await get(uri);
return response;
} catch (e) {
return Response(statusCode: 1, statusText: e.toString());
}
}
}
Also my local server is at http://127.0.0.1:8000 but in the Android Studio i gave it as 10.0.2.2:8000 then only I was able to load some images also I did some change in the manifest.xml you can find it below:
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:label="food_delivery_app"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
<!-- Required to query activities that can process text, see:
https://developer.android.com/training/package-visibility?hl=en and
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
<queries>
<intent>
<action android:name="android.intent.action.PROCESS_TEXT"/>
<data android:mimeType="text/plain"/>
</intent>
</queries>
</manifest>
Upvotes: 1
Views: 67
Reputation: 15
i think the problem was due to image size, when i deleted the images and added and lower size image(from 20 mb file to 200kb) it seems to load the image perfectly. I am using a Laravel backend i don't know why it is like that but reducing the file size seems to fix the issue for me.
Upvotes: 0