图像资源服务捕获异常:接收数据时连接关闭

问题描述 投票:0回答:1

我无法在我的 flutter 应用程序中加载图像,它给出了错误“图像资源服务捕获的异常” 解析图像编解码器时抛出以下 HttpException:

接收数据时连接关闭

flutter 应用程序中的图像部分完全空白。

下面是我的代码:

API代码:

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());
    }
  }
}

我的本地服务器位于http://127.0.0.1:8000,但在Android Studio中我将其指定为10.0.2.2:8000,然后只有我能够加载一些图像,我还在清单中做了一些更改。您可以在下面找到它:

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

android flutter dart
1个回答
0
投票

我认为问题是由于图像大小造成的,当我删除图像并添加较小尺寸的图像(从 20 mb 文件到 200kb)时,它似乎可以完美加载图像。我正在使用 Laravel 后端,我不知道为什么会这样,但减小文件大小似乎可以解决我的问题。

© www.soinside.com 2019 - 2024. All rights reserved.