0

过去几个月我一直在加载很多图像,但突然间,Flutter 没有加载任何图像。我检查了 pubspect.yaml,资产的名称和颤振医生没有给出任何错误。颤振医生:

[√] Flutter (Channel stable, v1.12.13+hotfix.5, on Microsoft Windows [Versión 10.0.18363.535], locale es-ES)
    • Flutter version 1.12.13+hotfix.5 at C:\flutter\flutter
    • Framework revision 27321ebbad (6 days ago), 2019-12-10 18:15:01 -0800
    • Engine revision 2994f7e1e6
    • Dart version 2.7.0

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at C:\Users\Victo\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
    • All Android licenses accepted.

[√] Android Studio (version 3.5)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 42.1.1
    • Dart plugin version 191.8593
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

[√] VS Code (version 1.41.0)
    • VS Code at C:\Users\Victo\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.7.1

[√] Connected device (1 available)
    • Android SDK built for x86 • emulator-5554 • android-x86 • Android 7.0 (API 24) (emulator)

• No issues found!

我的代码:

  Widget buildBg(context){
      return Stack(
        children: <Widget>[

          Container(
            child: Image.asset(
              'assets/images/FondoTiendas claro.jpg',
              height: MediaQuery.of(context).size.height,
              fit: BoxFit.cover,
              ),

          ),
          Container(
            decoration: BoxDecoration(
              gradient: LinearGradient(
                begin: Alignment.bottomRight,
                end: Alignment.centerLeft,
                colors: [Colors.white.withOpacity(0.5), Colors.transparent, Colors.white.withOpacity(0.5)],
              ),
            ),
          ),
        ],
      );
    }

上面的代码只是图像加载的一个例子。所有 image.asset 都给出了一个例外:

══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
I/flutter (32217): The following assertion was thrown resolving an image codec:
I/flutter (32217): Unable to load asset: assets/images/FondoTiendas claro.jpg
I/flutter (32217):
I/flutter (32217): When the exception was thrown, this was the stack:
I/flutter (32217): #0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
I/flutter (32217): <asynchronous suspension>
I/flutter (32217): #1      AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:484:44)I/flutter (32217): #2      AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:469:14)
I/flutter (32217): #3      ImageProvider.resolve.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:327:17)
I/flutter (32217): #4      ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:160:22)
I/flutter (32217): #5      ImageProvider.resolve.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:325:84)
I/flutter (32217): (elided 13 frames from package dart:async)
I/flutter (32217):
I/flutter (32217): Image provider: AssetImage(bundle: null, name: "assets/images/FondoTiendas claro.jpg")
I/flutter (32217): Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#b8720(), name:
I/flutter (32217):   "assets/images/FondoTiendas claro.jpg", scale: 1.0)
I/flutter (32217): ════════════════════════

pubspec.yaml:

flutter:
  fonts:
    - family: Helvetica
      fonts:
        - asset: assets/fonts/Helvetica.ttf
    - family: D-din
      fonts:
        - asset: assets/fonts/d-din.condensed.ttf
  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true
  assets:
    - assets/images/

另外,我已经尝试过flutter clean并在虚拟设备中重新安装该应用程序,但我不断收到错误消息。

4

1 回答 1

0

那是因为文件名。它里面有空间。只需将其重命名为FondoTiendas_claro.jpgor即可FondoTiendasclaro.jpg解决问题。

希望能帮助到你。

于 2019-12-17T04:51:09.963 回答