How to get latest version of package in flutter create template - flutter

I am modifying my default template file from my flutter installation directory here
C:\src\flutter\flutter\packages\flutter_tools\templates\app\pubspec.yaml.tmpl
dependencies:
#omitted
cupertino_icons: ^0.1.3
mobx: latest
flutter_mobx: latest
I am getting this error
Invalid version constraint: Could not parse version "latest". Unknown text at "latest".
How do i get the latest version instead of specifying specific version like ^1.x.x

There is no latest, you have to specify the version number or you can use any:
any
The string any allows any version. This is equivalent to an empty version constraint, but is more explicit. Although any is allowed, we don’t recommend it.
https://dart.dev/tools/pub/dependencies
To update your dependencies to the latest version you can do the following:
Use pub upgrade to update to the latest package versions that your pubspec allows. To identify dependencies in your app or package that aren’t on the latest stable versions, use pub outdated.

try this after the package that you want the latest
http: ^{latest version}

Related

Why is riverpod failing even to initialize in project? Method not found: 'Error.throwWithStackTrace'

So i am trying to get started with riverpod and creating a new flutter project with the "click and counter" default sample.
As soon as I add on the pubspec
flutter_hooks: ^0.18.0
hooks_riverpod: ^2.0.0
And
import 'package:hooks_riverpod/hooks_riverpod.dart';
I get this error on the debug console and can't figure it out what is the problem
: Error: Method not found: 'Error.throwWithStackTrace'.
../…/framework/provider_base.dart:904
Error.throwWithStackTrace(error, chain);
^^^^^^^^^^^^^^^^^^^
: Error: A non-null value must be returned since the return type 'Never' doesn't allow null.
../…/framework/provider_base.dart:898
Never _rethrowProviderError(Object error, StackTrace stackTrace) {
^
Error.throwWithStackTrace was added in Dart 2.16 (Flutter version 2.10 from Feb 8, 2022).
https://api.flutter.dev/flutter/dart-core/Error/throwWithStackTrace.html
(Check the #Since annotation.)
If your Flutter/Dart version is below that, you'll get the error you saw.
Two options that may help are:
Specify an exact version of dependencies (don't use ^ ahead of version)
upgrade Flutter/Dart to at least 2.10/2.16
flutter upgrade
If your problematic package (hooks_riverpod: ^2.0.0 in your case) is listed with ^, it'll use the latest version that doesn't break dependencies.
I'm guessing that when you created a new project and used that same dependency version, upon initial pub get it downloaded a newer version of the package (or a newer version of a dependency that that package uses) into "pub cache" which is relying on the new Error API method.
Your project will store this information in:
<your_project_dir>/dart_tool/package_config.json
The min Dart SDK version listed for the package should normally have changed from 2.12 to 2.16. (update: it's been updated now) This would give us a hint that we need to update our Flutter/Dart if we see our build failing.
In an earlier version of this answer, I noted that the ^ prefix on package dependency versions is supposed to prevent these types of issues, but I'm no longer certain it was meant to cover this situation where the underlying platform needs to be updated (as opposed to a breaking change in the API of the package itself).
Anyways, at first glance, it might make sense to go from 2.0.0 to 3.0.0 for a package version # when it depends on a new core Dart API method that did not exist when 2.0.0 was published.
Notes
The author of riverpod also wrote the new API for Error.throwWithStackTrace so likely the latest version of hooks_riverpod is using the latest API changes. (The version you're listing 2.0.0 is pre-release currently). You could try earlier versions of riverpod in your pubspec.yaml (such as 1.0.3)
for anyone facing " Method not found: 'Error.throwWithStackTrace' " with firebase.
try to add this to your pubspec.yaml
dependency_overrides:
firebase_messaging_platform_interface: 3.1.6
I saw this.
How about trying flutter pub upgrade?
If it is not resolved, then check analyzer version and check which dependency locks that.
As noted in Baker's answer, Error.throwWithStackTrace was recently added in Dart 2.16.
If you're getting an error about Error.throwWithStackTrace not being found for some package, the package author neglected to update their package's minimum Dart SDK version. You should report that to the package maintainer. In the meantime, you should use an earlier version of the problematic package or use a newer version of the Dart SDK.
Try running flutter upgrade
By this it will upgrade your flutter and dart SDK version and hope it resolves your issue
if you are still facing the issues after "flutter upgrade" or you use this line of code in pubspec.yaml
dependency_overrides:
firebase_messaging_platform_interface: 3.1.6
you receive this type of errors
java.lang.AssertionError: annotationType(): unrecognized Attribute name MODULE (class com.sun.tools.javac.util.UnsharedNameTable$NameImpl)
at com.sun.tools.javac.util.Assert.error(Assert.java:133)
at com.sun.tools.javac.code.TypeAnnotations.annotationType(TypeAnnotations.java:231)
at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.separateAnnotationsKinds(TypeAnnotations.java:294)
at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.visitMethodDef(TypeAnnotations.java:1066)
at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.scan(TypeAnnotations.java:275)
at com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:57)
so Try to upgrade your gradle version, this line in your build.gradle
classpath 'com.android.tools.build:gradle:4.1.0'
after doing that it may be possible it ask you to change your
gradle-wrapper.properties
distributionUrl=https://services.gradle.org/distributions/gradle-6.1.1-all.zip
to
distributionUrl=https://services.gradle.org/distributions/gradle-6.5-all.zip
also upgarde this packages
firebase_core: ^1.10.0
firebase_messaging: ^11.1.0

Version solving for certain package versions failed in flutter

I have received this kind error a couple of time before with different packages, usually i just try a combination of different versions till i finally get a match that works. Is there a way to know what package versions are compatible instead of using the trial error approach which is outright time consuming and exhausting.
Initially i though it could be that one of the packages depends on the other, like in this case maybe flutter_svg depends on a different version of flutter_luban so the version in my pubspec clashes with it, but none of these packages depend on one another after viewing the respective package dependencies.
pub get failed (1; So, because sakaHapa depends on both
flutter_svg ^0.17.4 and flutter_luban ^0.1.13, version solving
failed.)
You can use 'pub outdated' command like below.
https://dart.dev/tools/pub/cmd/pub-outdated
Here is column what means.
Current
The version used in your package, as recorded in pubspec.lock. If the package isn’t in pubspec.lock, the value is -.
Upgradable
The latest version allowed by your pubspec.yaml file. This is the version that dart pub upgrade resolves to. The value is - if the value in the Current column is -.
Resolvable
The latest version that can be resolved, when combined with all other dependencies. This version corresponds to what dart pub upgrade gives you if all version constraints in pubspec.yaml are unbounded. A value of - means that the package won’t be needed.
Latest
The latest version of the package available, excluding prereleases unless you use the option --prereleases.
flutter pub outdated

Flutter version constraints missunderstanding

is that means that if i use a package version ^2.0.1 that means if the developer of this certain packages update his package to 3.0.0, my application, which including this package will lose it although my application is released?
No, dependencies are only resolved at compile time. Once your application is released, those obviously won't change.
No, if you have ^2.0.1 in your pubspec.yaml and run pub get the most recent version will be locked into pubspec.lock - let's say your dependency has released version 2.0.4 then pubspec.lock will contain that information. For applications it is hence recommended that you add pubspec.lock to your version control. Subsequent pub get will always fetch the locked 2.0.4 until you either change something in your dependencies or run pub upgrade. If you run pub upgrade and the package author has release 2.3.0 this new version will be included. On the other hand if the package author releases 3.0.0 it will still not be used, because ^2.0.1 means the same as >=2.0.1 <3.0.0

Dart 2.6 and Flutter, Upgrading Dependency

Using Flutter, I am trying to update my dart dependency 2.6.0 but I get an error
Because *project_name* requires SDK version >=2.6.0 <3.0.0, version solving failed.
pub get failed (1)
exit code 1
I want to use the new features that dart offers, such as Extension Methods. How could I go about upgrading my dependency? I have installed the newest stable version of dart on my computer, but regardless I still get that error.
A couple of things that might help:
From this issue, you can try ensuring that you've updated enviroment in your pubspec.yaml file like so:
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
Another thing that might help is just double checking the steps in this post or on the dart installation page to ensure that you've updated to the latest version correctly.

How to determine the tag to Downgrade flutter from 2.0? Cannot build project anymore

I just updated my flutter and my project is not building anymore. I am getting the following error
Because project depends on progress_hud >=0.1.1 which requires SDK
version >=1.23.0 <2.0.0, version solving failed.
pub upgrade failed (1)
Now I read this link here which states that I should checkout that specific Tag. How do I know which Tag is associated with which branch ? Essentially I would like anything closer less than 2.0. Preferably 1.9 or something like that. How do I determine which tag that is?
Don't downgrade your Dart version, there is an issue with that package, it doesn't have the constraints updated : https://github.com/rcpassos/progress_hud/blob/master/pubspec.yaml
As you can see these constraints:
environment:
sdk: ">=1.23.0 <2.0.0"
Doesn't allow to build your app, you have two options:
wait for the owner to update the constraints
Use a fork from another user with the constraints updated, like
this:
Instead of this :
dependencies:
progress_hud: ^1.0.0
Use this:
dependencies:
progress_hud:
git: https://github.com/LampeMW/progress_hud/
Don't Downgrade Flutter. Instead add following tags in
pubspec.yaml
dependency_overrides:
shared_preferences: ">=0.5.12+4"
place your problematic packages lower versions.