Expected "assets" to be a list, but got -assets/image/ (String)
Solution 1
I had the same error I figured out that you must add assets like following:
Flutter uses the 'pubspec.yaml' file, located at the root of your project, to identify assets required by an app. Here is an example:
flutter:
assets:
- assets/my_icon.png
- assets/background.png
To include all assets under a directory, specify the directory name with the / character at the end:
assets:
- directory/
- directory/subdirectory/
Now lets come to your Error
Expected "assets" to be a list, but got -assets/image/ (String).
This Error has occurred as you did not add space between "- and assets". If you just add space It should solve your problem.
Solution 2
Using the correct format in pubspec.yaml file is very important. use:
assets:
- assets/images
(space between the strings -
and assets/images
is necessary)
Solution 3
You need to put a space between dash(-) and the "assets"
- assets/image/
Solution 4
flutter returns this error because the input is not correctly formatted.
the correct format is as follows
flutter:
assets:
-folder/file.png
Solution 5
uses-material-design: true
# To add assets to your application, add an assets section, like this: assets: - images/pic.jpeg - images/pic1.jpeg
aligned uses-material-design: true and assets: to the margin then flutter clean then flutter run
Deepank choudhary
Updated on December 12, 2022Comments
-
Deepank choudhary over 1 year
I am getting the following exception in my pubspec.yaml file :
Error detected in pubspec.yaml: Expected "assets" to be a list, but got -assets/image/ (String). Please correct the pubspec.yaml file at D:\Working_Project\FlutterProject\flutter_change_color\pubspec.yaml
-
ibhavikmakwana about 4 yearsPlease share your pubspec.yaml file here.
-
Oussama L. about 4 yearssuggest you give some more context
-
-
petras J almost 3 yearsThis solved my problem. The space does matter.
-
GuedesBF almost 3 yearsA bit of an overkill, is'nt it?
-
GuedesBF almost 3 yearsThis does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker.
-
user123456 over 2 yearsu need a space after the_