I can add a package to my pubspec.yaml file from command line using:
dart pub add foo
But how to add multiple packages?
dart pub add foo, bar // Doesn't work
Right now (Dart 2.15.1), the Dart pub tool does not support adding multiple package dependencies in one command. You therefore need to run pub add for each package you want to add as dependency for your project.
A pull request for pub have recently being merged which adds support for adding multiple dependencies in one operation.
You can find the issue here: https://github.com/dart-lang/pub/issues/3273
And pull request here: https://github.com/dart-lang/pub/pull/3283
Since this has happen rather recent, my own personal guess is, that this change is not going to be part of Dart 2.16 but rather Dart 2.17, since 2.16 has been closed for further development for some time to make it ready for release in the near future.
In bash:
for pkg in redux flutter_redux redux_sagas do; flutter pub add $pkg; done;
Obv add more packages as desired, space separated.
Related
I have been using flutter pub get for updating pubspect.yaml
Now I have found that there is a similar command dart pub get
What are the differences between these two commands?
Using the command flutter pub get you are getting dart packages for Flutter.
Using dart pub get you are getting Dart packages.
You can create dart projects without Flutter and there you’ll need use the command dart pub get.
Every Flutter project is a Dart project
but not every Dart project is a Flutter project, because Flutter is a UI kit or framework for building UIs in the Dart programming language.
When dart pub get gets new dependencies, it writes a lockfile to ensure that future gets will use the same versions of those dependencies. Application packages should check in the lockfile to source control; this ensures the application will use the exact same versions of all dependencies for all developers and when deployed to production. Library packages should not check in the lockfile, though, since they’re expected to work with a range of dependency versions.
If a lockfile already exists, dart pub get uses the versions of dependencies locked in it if possible. If a dependency isn’t locked, pub gets the latest version of that dependency that satisfies all the version constraints. This is the primary difference between dart pub get and dart pub upgrade, which always tries to get the latest versions of all dependencies.
When running flutter pub get (Packages get in IntelliJ or Android Studio) for the first time after adding a package, Flutter saves the concrete package version found in the pubspec.lock lockfile. This ensures that you get the same version again if you, or another developer on your team, run flutter pub get.
Dart: How to determine which pub package is discontinued?
I have a long list of packages. When I run dart pub upgrade it says that one is discontinued. Is there a command to list which one is discontinued?
Use the following combination of commands:
dart pub upgrade --dry-run | grep discontinued
In the resulting long list of packages from the dart pub upgrade command, I did not at first notice that "discontinued" is printed in parenthesis inline with the corresponding package. The above command combo will find those lines for you.
It's possible that the discontinued package is not in your direct pubspec packages, but buried deep in their dependencies. In my case, the "pedantic" package is discontinued, and that is still used by many other packages.
[EDIT]
In my original answer, I mixed up and put the incorrect command, which one of the comments references. "outdated" does not return discontinued. I corrected the command above. This was my original incorrect command.
dart pub outdated | grep discontinued
I created a package that is a collection of my own helper classes for faster developing...
The package also included firebase_analytics: which requires a native implementation for each platform i want it to run. Even if i dont wanted to use firebase at all, but still wanted to use my package i was forced to create firebase-config files for the app, because the app crashes if the firebase_analytics package does not find a valid file for the specific platform. To avoid those things i splitted my package in two packages.
The Core-Package: All helper classes that run native dart code
Optional extension: Only the classes that need the firebase implementation
So if i want to use the package without firebase i just have to depend on the core.
If i want to use the firebase variant i could simply depend the firebase package, because the extension package itself depends on the core-package in its own pubspec.yaml file.
PROBLEM: Since i restructured my package like i described, all my apps that depend on it are not building anymore. The console says that all packages that i depend on in my two packages can not be found. This error occures both ways: With firebase & without.
ERROR: (Scroll down for the complete console output)
MY ATTEMPTS:
"flutter clean" & "flutter pub get" in every package and app folder
"flutter pub cache repair"
CORE-PACKAGE Pubspec.yaml:
FIREBASE-Extension Pubspec.yaml:
Plain Console Output:
pastebin.com/m14cbqDV
Thanks for any help!!
I am facing the same issue while i was making a build in Xcode 13.So I had upgraded my flutter version 2.8.0 to 2.10.2 and also removed the version of all firebase dependencies, then the issue was finally solved.
I have faced similar issues and resolved them by removing package versions. Issues like this often arise due to mismatched versions of packages (eg firebase_core, firebase analytics). Please try to remove versions of the firebase packages or the whole packages. (like firebase_analytics :).
Sorry, my bad! As you can see i moved my dependencys to the dev section of my pubspec.yaml. They should be placed in the dependency section.
Lets say I am starting a new dart project. I have a few packages on pub.dev I know that I want to use, and I want to use the most recent version of these packages.
Right now, I open my browser and go to pub.dev and find each package, then check the Versions or Installing tab to find out what the latest version is so I can put that in my pubspec.yaml. Then I can run pub get
Using npm, you can run npm install <package> and npm will automatically fetch the latest version of the package and add it to package.json
Is there a pub command, syntax for pubspec.yaml, or something else that will make pub resolve the latest version of a package and use it in my project, without having to manually look up the latest version?
Normally in Flutter, the packages which you want to use need to be added to pubspec.yaml and run pub get. But there are also some IDE plugins like npm.
For example, Pubspec Assist is using on Visual Studio, you can add or update your dependencies without going pub.dev. But you have to know which packages do you want to use at least for a time.
https://marketplace.visualstudio.com/items?itemName=jeroen-meijer.pubspec-assist
Simply enter the following command in the terminal
flutter pub add provider
Of course, where it says provider, put the package you want to install.
The package with the latest version is automatically added to your pubspec.yaml.
Otherwise you can always do what #jamesdlin said and leave the version field empty.
Does anyone know if you can do reproducible builds in Flutter? There doesn't seem to be an option to install from the pubspec.lock file. I would of expected something like:
flutter pub get --from-lockfile
The problem is that the pubspec.lock is modified on every run of flutter pub get so I can't easily go back to the previous state of the dependencies at different points in the git history.
I would of expected it to behave like the yarn.lock or package-lock.json which allow you to create reproducible builds of the project.
As mentioned in the doc, pub get should fetch what's in pubspec.lock if the lockfile contains the solution for the dependency requirements and constraints configured in pubspec.yaml. Simply put, if pubspec.yaml and pubspec.lock isn't modified, and neither Dart nor Flutter SDK is upgraded, then pub get should fetch what's listed in pubspec.lock.
If you're still having issues and can be reproducible, you can file an issue here https://github.com/dart-lang/pub/issues - as jonasfj also mentioned in the Comments.