Migrating to Flutter 2 fail - flutter

I have a project that is developed with Flutter v1.22.6 and was working great, after updating the flutter to v2.0.0 and reading the documentation, I've found out I can use dart migrate --apply-changes to fix issues that are related to flutter upgrade, By running the command I get dozens of errors and the error ends with:
The migration tool didn't start, due to analysis errors.
The following steps might fix your problem:
1. Set the lower SDK constraint (in pubspec.yaml) to a version before 2.12.
2. Run `dart pub get`.
3. Try running `dart migrate` again.
What is the simplest way to migrate the current project to the v2?

The problem is that you have already migrated to a newer version of dart.
You can't migrate your projects from the new version, there is literally nothing to migrate to.
If you want to migrate your older projects (which are without null safety) to a new version, your dart version must be older than 2.12.0 version.
In this case, consider changing the version in your pubspec.yaml file.
environment:
sdk: '>=2.11.0 <3.0.0'
Then run the command in your terminal
> dart migrate --apply-changes

make sure you have following step by step migrate dart 2
and base on your error notification try to set in pubspec.yaml
environment:
# Works in Dart 2 only.
sdk: '>=2.0.0 <3.0.0'

Related

Bitrise flutter build keeps using older versions of flutter/dart

I have a flutter app that I am trying to build through bitrise.
I keep getting a tonne of errors along the lines of
Error: The 'super-parameters' language feature is disabled for this library.
Try removing the package language version or setting the language version to 2.17 or higher.
super.key
and it is blocking me from analyzing and building the app.
Now the issue is, I am using flutter install with upgrade set to true , and have sdk target in my pubspec.yaml as
Environment:
sdk: ">=2.17.6 <3.0.0"
I disabled the caching steps, and tried to create a new deployment pipeline, to no avail.
In your workflow, add Flutter Install, Then set your desired flutter version on Input Variables sections's Flutter SDK git repository version field. e.g. 2.8.0.

flutter : How migrate to Null safety

I have a project that is developed with Flutter v2.2.3 and Dart version 2.13.4 working great,I should migrate to Null safety , I upgraded sdk to 2.12.0 in pubspec.yaml but I got the error ends with:
The migration tool didn't start, due to analysis errors.
The following steps might fix your problem:
1. Set the lower SDK constraint (in pubspec.yaml) to a version before 2.12.
2. Run `dart pub get`.
3. Try running `dart migrate` again.
How I can get the url migration suggestions to complete migration task ?
How i can fix it ?
thank you in advance

Error when reading 'migrate': No such file or directory

I want to use migration tool as described here.
But I get Error: Error when reading 'migrate': No such file or directory
Here my dart version and error
xxx#xxx-:~/Desktop/xxx$ dart --version
Dart VM version: 2.4.0 (Unknown timestamp) on "linux_x64"
xxx#xxx-I:~/Desktop/xxx$ dart migrate
Error: Error when reading 'migrate': No such file or directory
pubspec.yaml
version: 1.0.0+1
environment:
sdk: ">=2.12.0 <3.0.0"
**
First solution :**
dart --version
If the dart sdk version is less than 2.12.0
Then try:
Flutter upgrade --force
or
dart upgrade
If dart migrate still doesn'tt work then jump to the second solution
Second solution :
since dart is already downloaded as part of flutter
Make sure first that it hasn't been downloaded twice
on Mac try :
where dart
on MS windows , check your path in the environment variables.
If there was more than one path for the dart sdk , then this is problem
In my case I had it installed twice
/usr/local/bin/dart
/Users/USER/Documents/flutter/bin/dart
so I removed the first one by (mac os)
rm /usr/local/bin/dart
The moment I did that the issue was fixed.
Try
dart --version
again and you should be having the latest version of dart that comes with flutter and you should be able to run succsfully
dart migrate

Using Futures in flutter old versions

Android studio is giving me this error
info: The class 'Future' wasn't exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.
If I put this
import 'dart:async';
the problem seems to go away. Could someone explain why this is happening and if this is the correct way to fix this.
Thanks a lot.
---- edit
Can I update dart core to something > 2.1
I am guess it is this line in my pubspec yaml
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
Is there any downsides to doing thins i.e. running on older android/ios versions.
Open the terminal and execute the following:
flutter upgrade
This will upgrade both flutter and dart

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.