i can not use either install the package
Update the dependencies in pubspec.yaml
use flutter pub upgrade
also, attach the description of the place where it is used.
Related
I want to build a package for Flutter and Dart, but I don't have any previous experience with package development. I am not sure how to create the package. Should I use
flutter create --template=package
or
dart create -t package
I want support for both Flutter and Dart.
I looked at the Flutter documentation on creating packages, but I couldn't understand if it would create a package with Flutter only support, or both Flutter and Dart support.
First, use the following command to check if your package meets all the requirements to publish the package.
dart pub publish --dry-run
Once you are sure that your package is ready to deploy on pub dev run this command:
dart pub publish
Coming from npm, I deeply dislike the way Google handles package updates within Flutter. Instead of updating the pubspec.yaml on flutter pub upgrade, it will only update the pubspec.lock.
To ensure that the pubspec.yaml is up to date, I have to run flutter pub outdated and manually adjust the pubspec.yaml before running flutter pub upgrade. I'm too lazy for that, it's no fun, I want this to be automated. The recommend versions of flutter pub outdated should be set in the pubspec.yaml for me.
How to I do that?
you can use Ctrl+Space after a package name in pubspec.yaml to get the latest version.
you must press Ctrl+Space exactly one space after ' : ' to see the latest version.
cupertino_icons: <click Ctrl+Space here>
I deleted a package manually from Dart Package directory and deleted pubspec.lock. Now when I do flutter pub get it does not download that package again. I tried flutter clean && flutter pub get but it's not working as well. Please help I can't build my project now.
You can try to close and then open the editor and try:
flutter clean
flutter packages get
flutter packages upgrade
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.
npm (and so yarn) has a greate feature that you can add needed packages just by knowing the package name (like yarn add xxx_yyy) and it adds the latest stable release to your project. Does flutter have any equivalent hero? Or we have to search our needed package on pub.dev and find version to add to our pubspec.yaml?
Add a package as a direct dependency:
flutter pub add <package-name>
Add a package as a dev-dependency:
flutter pub add -d <package-name>
Remove a package:
flutter pub remove <package-name>
Note: You can also use dart command instead of flutter above.
You can manage packages with flutter pub command.
flutter pub add - adds packages to your project's pubspec.yaml and downloads them. So you don't have to run flutter pub get.
flutter pub add <package>
Add a package to your project's dependencies.
flutter pub add --dev <package>
Similarly adds package to dev_dependencies.
flutter pub remove <package>
Removes the package from your project's dependencies.
Documentation: https://dart.dev/tools/pub/cmd
Note: (flutter pub is the same as dart pub)
Update 2
Based on #CopsOnRoad answer, now dart has add command which is the best way for adding packages from cmd. Full documentation is here.
Update
Right now you can have exactly similar experience like npm or yarn in flutter with the help of get_cli package. One of the tools it provides will let you just write the package name and it automatically installs the latest version with mentioning the version number inside the yaml file.
From its documentation
// To install a package in your project (dependencies):
get install camera
// To install several packages from your project:
get install http path camera
// To install a package with specific version:
get install path:1.6.4
// You can also specify several packages with version numbers
// To install a dev package in your project (dependencies_dev):
get install flutter_launcher_icons --dev
Old answer
About the cli verb add, there is no any equivalent in flutter and pub yet. But about the versioning and adding packages just with their names, try to add them in pubspec.yaml file without version number. Just like this:
dependencies:
http: ^0.12.0+2
mobx:
flutter_mobx:
dio: ^2.1.13