Reputation: 405
When I try to load image from the assets/images folder, it shows
The asset assets/images/waiting.png does not exist. Try creating the file or fixing the path to the file.
But the file is there. I have checked the directories manually through file explorer too.
flutter:
uses-material-design: true
assets:
- assets/images/waiting.png
I have tried a lot, but it doesn't work. Is that a bug or something? or my code problem?
name: flutter_expense_app
description: A new Flutter project.
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
intl: ^0.16.1
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
uses-material-design: true
assets:
- assets/images/waiting.png
# - assets/images/waiting.png
#- images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
fonts:
- family: OpenSans
fonts:
- asset: assets/fonts/OpenSans-Regular.ttf
- asset: assets/fonts/OpenSans-Bold.ttf
weight: 700
- family: Quicksand
fonts:
- asset: assets/fonts/Quicksand-Regular.ttf
- asset: assets/fonts/Quicksand-Bold.ttf
weight: 700
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
Upvotes: 3
Views: 7860
Reputation: 1
You can try this:
assets:
- lib/asset/images/burger.png
- lib/asset/images/cheese.png
Upvotes: 0
Reputation: 213
If you have provided the path correctly in the pubspec.yaml file as mentioned in the above answers but still the issue exists, check the location of the your assets folder. Make sure it is created outside of the lib folder of your flutter project.
Upvotes: 0
Reputation: 1
Check indentation of the assets in pubspec.yaml. It usually should start with 2 spaces from new line before assets, 3 spaces from new line with a - and 1 space followed by the the path to your assets. If it still doesn't work just close your code editor and re-open it.
Upvotes: 0
Reputation: 11
Try this:
flutter:
assets:
-android/assests/directory/
Upvotes: 0
Reputation: 1
If you using Windows instead of macOS, try to use file path with back slashes. For example "assets\fonts\Quicksand-Regular.ttf"
instead of "assets/fonts/Quicksand-Regular.ttf"
Upvotes: 0
Reputation: 759
I solved it by putting two spaces before the word "asserts" and three spaces before the horizontal line and one space after it. In this manner:
Upvotes: 0
Reputation: 2956
The issue is because of indentation. Try using a reformat of pubspec file and it will work perfectly.
Upvotes: 1