I am trying to migrate a project into null safety mode,after migrating and clearing all the errors, I am getting this problem named 'Sort pub dependencies.dart(sort_pub_dependencies)'. I searched Google but couldn't find any solution. Any help would really be appreciated :)
3 Answers
sort_pub_dependencies
is a lint that comes from the Dart linter: https://dart-lang.github.io/linter/lints/sort_pub_dependencies.html
The lint is activated in the analysis_options.yaml
file in your project.
linter:
rules:
- sort_pub_dependencies
Basically, it is telling you to sort the name of the dependencies alphabetically in the pubspec.yaml
dependencies:
markdown:
archive: # put archive before markdown
You can remove the line from analysis_options.yaml
if you don't want to enforce this rule.

- 3,647
- 24
- 17
-
3Sort dependencies by name? – Syed Ali Raza Apr 15 '21 at 10:23
-
@SyedAliRazaBokhari Yes – MSARKrish Jul 11 '22 at 17:00
-
Removing linter is not a solution right? – Shailendra Madda Jun 15 '23 at 09:06
It isn't a necessary rule, you can just turn that off by going to your analysis_options.yaml file and adding this line under rules:
sort_pub_dependencies: false

- 529
- 1
- 5
- 25
There is also a package for sorting the dependecies with more features on pub.dev.
You add the package to your dev_dependencies
section in pubspec.yaml file or use flutter pub add --dev pubspec_dependency_sorter
.
Then run
flutter pub run pubspec_dependency_sorter
The packages will be automatically sorted for you.

- 2,405
- 1
- 25
- 40

- 41
- 2
-
Please don't just post some tool or library as an answer. At least demonstrate [how it solves the problem](//meta.stackoverflow.com/a/251605) in the answer itself. – 4b0 Sep 23 '22 at 08:50
-
1