Search code examples
flutterdartflutter-image

Flutter does not load images any more


I have been loading a lot of images for the last months but suddenly, Flutter doesn't load any image. I have checked the pubspect.yaml, the names of the assets and flutter doctor does not give any error. flutter doctor:

[√] 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!

My code:

  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)],
              ),
            ),
          ),
        ],
      );
    }

The code above is just one example of image loading. All of the image.asset give an exception:

══╡ 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/

In addition, I have already tried flutter clean and reinstalling the app in the virtual device yet I keep getting errors.


Solution

  • That's because of the filename. It has space in it. Just rename it to FondoTiendas_claro.jpg or FondoTiendasclaro.jpg and that should resolve the issue.

    Hope it helps.