Reputation: 459
I keep getting
Running "flutter packages get" in flutter_sportters...
Error on line 6, column 5 of pubspec.yaml: A dependency may only have one source.
sdk: flutter
^^^^^^^^^^^^^
When I run my app
or Packages Get
.
It worked perfectly fine before. Have no idea how to fix this.
Upvotes: 45
Views: 65625
Reputation: 333
Use This extension for batter experience : YAML
Example:
Happy coding🧑💻.
Upvotes: 0
Reputation: 458
make sure, the name of your project is not same as any package , this too cause for this error
Upvotes: 1
Reputation: 365
Check indentations as flutter package in pubspec.yaml
takes single dependency source.
Upvotes: 3
Reputation: 3168
I was trying to add assets
folder to my project. I added it under dependencies
which caused the error:
dependencies:
flutter:
sdk: flutter
assets:
- images/
It's not to be added under dependencies
. Instead, add it under flutter
:
flutter:
uses-material-design: true
assets:
- images/
Upvotes: 10
Reputation: 3829
After checking all other solutions if the problem still persists make sure whether the specified library is installed correctly or not. This error also encounter when the library is not installed correctly.
Upvotes: 0
Reputation: 73
I ran into the same problem turns out the name of my app and the package name were same which resulted into this error.
name of the app scrapy and the dependency was also scrapy...
Changed the name and it worked.
Upvotes: 0
Reputation: 330
Its due to indentation: check out correct way
name: flutter_app description: A new Flutter application.
environment: sdk: ">=2.1.0 <3.0.0"
dependencies: flutter: sdk: flutter http: "0.11.3+17" autocomplete_textfield: ^1.6.4
dev_dependencies: flutter_test: sdk: flutter
flutter: uses-material-design: true
Upvotes: 0
Reputation: 367
Indentation !!! Being newbees making silly mistakes. I have written the new dependency inside the flutter root as :
dependencies:
flutter:
sdk: flutter
sqflite:
Instead of
dependencies:
flutter:
sdk: flutter
sqflite:
Comment when you see the difference!!
Upvotes: 18
Reputation: 728
I solve My problem:
Here my first Code
dependencies
flutter:
sdk: flutter
webfeed: ^0.4.2
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
after I change it
dependencies:
flutter:
sdk: flutter
webfeed: ^0.4.2
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
I thing you must to put your package name in the same number colunm of flutter:
and cupertino_icons:
Upvotes: 4
Reputation: 521
I am getting this error due to duplication of a package in dependencies i.e: dependencies:
flutter: sdk: flutter
**cupertino_icons: ^0.1.2**
english_words: ^3.1.5
# The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
I solved this error by removing duplication then Flutter clean and then Flutter Packages Get.
Upvotes: 0
Reputation: 1
I kept getting this error no matter what I did, including commenting out the new lines. Finally, I put them back in with the correct indentation and ran the program. The problem magically resolved itself. However, the indentation is critical.
Upvotes: 0
Reputation: 85
Other answers are correct. I would also like to add that I was trying to add shared_preferences
and even though my indentation was correct, I was still getting the error mentioned in the question. To resolve it I changed the name of my project as it was also shared preferences
Upvotes: 0
Reputation: 11
open your pubspec.yaml file
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
country_code_picker: ^1.0.4
Upvotes: 0
Reputation: 2858
It throws an error because of Indention. It is important to maintain Indention while adding a dependency in flutter.
Before :
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
english_words: ^3.1.0
After :
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
english_words: ^3.1.0
Hope this will solve your error. Happy coding!!!
Upvotes: 46
Reputation: 2723
Consider you are going to use this package "shared_preferences".
You will get this error in pubspec.yaml. If you did like below.
dependencies:
flutter:
sdk: flutter
shared_preferences: v0.4.2
Indention is important you are accidentally adding shared_preference package below flutter dependency. So the error "A dependency may only have one source"
Correct format below:
dependencies:
flutter:
sdk: flutter
shared_preferences: v0.4.2 #no indention
Upvotes: 97
Reputation: 9375
You can define just like that in pubspec.yaml file
dependencies:
flutter:
sdk: flutter
image_picker: 0.4.1
and flutter packages get you can call via terminal or if you are using Android Studio than options availbale above when you edit pubspec.yaml file.
In terminal go to your project directory and then enter flutter packages get
Upvotes: 5