Differences dart pub get and flutter pub get - flutter

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.

Related

How to create a package with support for both flutter and dart at the same time

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

flutter migration to null-safety - how fix "Bad state: Error: package has unmigrated dependencies"?

I have a pretty big Flutter project, I'm currently adding null-safety support. My project consists of several parts - the "core" and "client".
"Client" used "core"
environment:
sdk: ">=2.10.0 <3.0.0"
.....
app_core:
path: ../core
First I updated the core with command
dart migrate
Now I when run "dart migrate"(in core) - I get this result:
All sources appear to be already migrated. Nothing to do.
Now I try to update the "client" part, I run the following commands
dart pub outdated --mode=null-safety
[✗] indicates versions without null safety support.
[✓] indicates versions opting in to null safety.
All your dependencies declare support for null-safety.
Next step:
dart pub upgrade --null-safety
Changed 1 dependency!
1 package is discontinued.
24 packages have newer versions incompatible with dependency constraints.
Try `dart pub outdated` for more information.
No changes to pubspec.yaml!
Next step:
dart pub get
When I run
dart migrate
I get these messages:
Bad state: Error: package has unmigrated dependencies.
Before migrating your package, we recommend ensuring that every library it
(either directly or indirectly) has been migrated to null safety, so
that you will be able to run your unit tests in sound null checking mode. You
are currently importing the following non-null-safe libraries:
...//file list
..............
Please upgrade the packages containing these libraries to null
safe versions
before continuing. To see what null safe package versions are
available, run
the following command: `dart pub outdated --mode=null-safety`.
To skip this check and try to migrate anyway, re-run with the
flag
`--skip-import-check`.
"file list" - is a large list of files from "client" (I did not find any regularity in it). Also, these files have no errors.
What is the reason for these warnings?
How can I fix it? Any advice - I will be grateful.

Getting an error when running "flutter pub get"

I have cloned a Repo of a Flutter project from my developer who has the App working perfectly on his machine, and opened the project in VS Code. I did flutter clean, then flutter pub get, and am getting an error as shown below. AFAIK when I clone the repo, I should get his exact files, so I don't understand how I am getting this error, but he does not? Does anyone know how to fix this? TIA for any and all help.
Because every version of charts_flutter from git depends on logging ^1.0.2 and signalr_client >=0.1.3 depends on logging ^0.11.3+2, charts_flutter from git is incompatible with signalr_client >=0.1.3.
So, because app1 depends on both signalr_client ^0.1.6 and charts_flutter from git, version solving failed.
Running "flutter pub get" in App1...
pub get failed (1; So, because app1 depends on both signalr_client ^0.1.6 and charts_flutter from git, version solving failed.)
The reason is simple
The both two packages depends on one common package
Signalr_client & Charts Flutter packages needs the logging package as a dependency.
See the pubspec file
https://github.com/soernt/signalr_client/blob/master/pubspec.yaml
https://github.com/google/charts/blob/master/charts_flutter/pubspec.yaml
But the versions are different for that.
Solution:
Try to remove the logger package from the pub_cache folder.
remote any one package signalr_client or charts_flutter.
use syncfusion_charts instead of charts_flutter
Try to update the flutter packages

Flutter | Error: Couldn't resolve the package

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.

flutter pub outdated for a specific package?

When I run
flutter pub outdated
it gives me a list of all the packages I have in pubspec.yaml which are outdated. What if I have more than 100 packages in it, I'd like to know is there any command or way (except searching in terminal) to find out the information provided by above command but only for that package, something like:
flutter pub outdated xyz
where xyz is my package.
For Android Studio and IntelliJ, use Flutter pub version checker
For Visual Studio Code, use Pubspec assist
There is this plugin for Android Studio called Flutter enhancement suite which automatically detects outdated packages and suggests updates for you inside pubspec.yaml file