Reputation: 3
I'm new to flutter app development and trying to display and image in the app and below is the error I get when I run the app and my code snippet too, help a novice please.
Launching lib/main.dart on iPhone XR in debug mode...
Running Xcode build...
Xcode build done. 21.3s
Syncing files to device iPhone XR...
flutter: ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
flutter: The following assertion was thrown resolving an image codec:
flutter: Unable to load asset: assets/images/GEJ.jpg
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
flutter: <asynchronous suspension>
flutter: #1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:433:44)
flutter: <asynchronous suspension>
flutter: #2 AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:418:14)
flutter: #3 ImageProvider.resolve.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:285:105)
flutter: #4 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:157:22)
flutter: #5 ImageProvider.resolve.<anonymous closure> (package:flutter/src/painting/image_provider.dart:285:82)
flutter: (elided 13 frames from package dart:async)
flutter:
flutter: Image provider: AssetImage(bundle: null, name: "assets/images/GEJ.jpg")
flutter: Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#266bb(), name: "assets/images/GEJ.jpg",
flutter: scale: 1.0)
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
Code Snippet:
child: Image.asset(
'assets/images/GEJ.jpg',
fit: BoxFit.cover,
),
PS: Below is my pubspec.yaml
info:
environment: sdk: ">=2.1.0 <3.0.0" dependencies: flutter: sdk: flutter cupertino_icons: ^0.1.2 dev_dependencies: flutter_test: sdk: flutter flutter: assets: - assets/images/GEJ.jpg
Also when i indent the asset: one more, it says The assets does not exist
Upvotes: 0
Views: 723
Reputation: 267554
You need to make new folder called images
in your assets
folder and have your image file in it. Like this:
com.yourpackage.app
- assets
- images
- GEJ.jpg
Once done, you need to run flutter packages get
command in terminal window or you can use IDE option that reads Packages get
when you're in pubspec.yaml
file
Upvotes: 1