How do I upgrade an existing Flutter app? - flutter

I have an existing Flutter app that I built half a year ago. I checked on pubspec.lock, it has this line:
sdks:
dart: ">=2.10.0-110 <2.11.0"
flutter: ">=1.16.0 <2.0.0"
So I assume the app was built for Flutter v1.16.
How do I upgrade this app to use the latest Flutter's version? Running "flutter doctor" gives me [√] Flutter (Channel stable, 1.22.3, on Microsoft Windows [Version 10.0.19041.630], locale en-US), so my SDK is already updated to the latest version.
Interestingly, when I create a new app from scratch, the pubspec.lock does not have any information about the Flutter's version. The same section now contains only this: sdks: dart: ">=2.10.0-110 <2.11.0". In the future, how would I know which version was this app running?
I have tried running "flutter upgrade" within my app, but that was to upgrade the SDK, not the Flutter version of the app. So how do I upgrade my app to use the latest Flutter version? Or is it always built using the latest version of the SDK? Can't I target my app to build with specific version of Flutter?

To update the project to null safety follow these steps:
Side note: change the flutter version in pubsec.yaml, make new project and copy the following line:
sdk: ">=2.12.0 <3.0.0"
Then follow the steps:
Run flutter upgrade in the terminal to upgrade Flutter
Run dart migrate to run the dart migration tool.
Solve all errors which the migration tool shows.
Run flutter pub outdated --mode=null-safety to print all outdated packages.
Run flutter pub upgrade --null-safety to upgrade all packages automatically.
Check the code for errors and solve them (Very important).
Run dart migrate again and it should now be successful. Follow the link to checkout the proposed changes.
Press the "Apply Migration" button.
Check the code for errors again and fix them.
Your project should be updated now.
Referenced from this website.

Go ro the root directory of your flutter project and run flutter upgrade. This will upgrade both your existing flutter project and flutter SDK to latest version.
Run the command:
flutter upgrade
Additional for upgrading to latest stable version only
If you want to upgrade to latest version only then please first check your current flutter channel
Step 1:
Check for Stable channel
flutter channel
You will get output like this:
beta
dev
master
* stable
If output was not like this then please proceed to Step 2 or directly proceed to Step 3
Step 2:
Switch to flutter stable channel
flutter channel stable
Now you will get output like this:
beta
dev
master
* stable
Step 3:
Run the below command to upgrade to latest stable version of flutter
flutter upgrade

Inside your project root, run below command
flutter upgrade
This command will update the Flutter SDK locally installed on your workstation, wondering how does that make sense?
After you run, above command flutter upgrade the SDK is updated locally and whenever you build or run your flutter app now, it should always pick up the latest stable version (stable channel) installed locally.
to check run,
flutter channel
you should get something like below based on what version is installed locally on your workstation.
Flutter is already up to date on channel stable
Flutter 2.0.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 4d7946a68d (3 days ago) • 2021-03-18 17:24:33 -0700
Engine • revision 3459eb2436
Tools • Dart 2.12.2
You can always switch to a different channel with below command,
flutter channel dev
flutter upgrade
Answer to - the Flutter SDK locally installed on your workstation, wondering how does that make sense?
Open your pubspec.yml file and see below:
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
Where version: 1.0.0+1 is your flutter app version
When you run command flutter run your app should pick up the environment as defined which is sdk: ">=2.1.0 <3.0.0"
With all dependencies as defined under,
dependencies:
flutter:
sdk: flutter
where sdk: flutter states that the SDK should be pulled from your locally installed SDK version.
Recall, how you had installed the Flutter SDK first time, on your local workstation, as below MAC example, See all SDK releases
cd ~/development
unzip ~/Downloads/flutter_macos_2.0.3-stable.zip
later, Update your path, and run flutter doctor.
OR
git clone https://github.com/flutter/flutter.git -b stable
later, Update your path, and run flutter doctor.
Note: You may check your pubspec.lock file that may look like below,
sdks:
dart: ">=2.12.0-0.0 <3.0.0"
flutter: ">=1.16.0" <---- Use SDK greater than this installed locally

I will show you an easy way to migrate old code projects.
My recommendation is not to work on the existing old project. Instead, create a new project where you can turn your existing project code into new clean, tidy code at a time.
Now put a line of code on the existing old code project terminal as below.
$ flutter create -t <project-type> <new-project-path>
For example, your terminal code like,
PS C:\Users\habib\VScodeProject\git_ripository\simple-weather-old> flutter create -t app C:\Users\habib\VScodeProject\git_ripository\simple-weather-new
Done.
After that, Your new project will no more show any system problems, like gradle problem, android manifesto problem i.e.
If you want to see more about flutter migrating: [See this flutter doc]

if you upgrade your project, but still have problem. then please check your path spellin is ok or not!?
I also face this problem. after upgrading project it won't work for me. then i look to my code, there was miss path.

Related

The current Dart SDK version is 2.15.1 in flutter

I'm getting this error for a very long time.
I tried uninstalling vs code
flutter clean
and reupdating the flutter SDK version.
even after that no success. I'm new to flutter and help me to solve the error
Highest dart version on flutters stable channel is 2.17.6 and on beta channel it is 2.18.0. To use dart SDK 2.19.something I'm guessing you'd have to step up on flutters master channel.
IF you want that, run:
flutter channel master
flutter upgrade
But why do you have such high sdk requirements in your pubspec.yaml ? Maybe this is enough? I'm thinking that it should be... so just update your pubspec.yaml file
environment:
sdk: ">=2.15.1 <3.0.0"

Not possible downgrade to Flutter 1.22.6

I am trying to downgrade my Flutter version to 1.22.6
I am using Flutter channel stable.
This is the output when I put in the terminal the command
flutter downgrade 1.22.6
There is no previously recorded version for channel "stable"
Yesterday was the last time I could downgrade to Flutter 1.22.6
Are there any changes in Flutter lastly?
Version 1.22.6 is listed in https://docs.flutter.dev/development/tools/sdk/releases?tab=macos
Should I download the SDK by hand?
It's no more possible to downgrade from flutter 2.xx to 1.xx. However you can use flutter Version Manager fvm its specifically made to control flutter versions plus along with that you can install flutter sidekick as well.Use multiple versions of flutter specific for your projects I am attaching link for you.
FVM Flutter Sidekick

Unable to add google_sign_in to flutter project, package requires older version of Flutter SDK?

New to Flutter so sorry about the question. Tried to change the environment but project won't build.
The current Flutter SDK version is 1.9.1+hotfix.6.
Because solemaster depends on google_sign_in >=4.0.16 which requires Flutter SDK version
>=1.10.0 <2.0.0, version solving failed.
pub get failed (1)
environment:
sdk: ">=2.1.0 <3.0.0"
The flutter SDK version you're using is older than the required by the library. You're confusing the Flutter SDK with the Dart SDK. The Dark SDK is the environment on the code you provided.
google_sign_in is based on the Flutter beta channel, instead of the stable channel. (p.s. this channel is where you get your flutter updates from).
From there, you have two options:
Use an older version of google_sign_in. Version 4.0.15 or 4.0.14 should do the trick, since this change was published today as said on the changelog.
On the pubspec.yaml file, change the current declaration to google_sign_in: 4.0.15.
Change to the beta channel. Keep in mind that the Flutter versions here are being tested, so you may experience some issues. To change channel, run flutter channel beta, then flutter upgrade.
try
flutter pub cache repair
flutter clean

How to downgrade your flutter SDK version?

My current Dart SDK Version is 2.1.2-dev.0.0.flutter-0a7dcf17eb.
However i need to use a flutter text recognition Dependency that requires SDK version >=1.23.0 <2.0.0
How can I downgrade my version?
In the Flutter install directory execute
git checkout v1.2.2
Now run
flutter doctor
You can just go from a version to another using the new commands
flutter downgrade -> go to the previous
flutter upgrade -> update to the new one
If you have a specific version of Flutter that you want to switch to (e.g. a previous stable version), you can use the flutter version command:
First find the version you wish to switch to here: https://flutter.dev/docs/development/tools/sdk/releases
Then, use flutter version command:
flutter version v1.9.1+hotfix.3
To pin Flutter package to a specific version, specify Flutter version explicitly in the pubspec.yaml file environment section:
environment:
sdk: '>=1.19.0 <3.0.0'
flutter: ^0.1.2
You have to run one command
flutter version
Above command shows you list of flutter version after that you can choose any version from that list. Using for example flutter version v1.9.1+hotfix.6

How to run flutter projects with different/older Dart SDK dependencies?

The current Dart SDK version is 2.1.0-dev.9.4.flutter-f9ebf21297.
Because NewsBuzz requires SDK version >=1.8.0 <2.0.0, version solving failed.
I am trying to run projects from https://startflutter.com. There are several older projects using older versions of Dart SDK or with dependencies requiring older Dart SDK version.
Is there any way to run multiple versions of Dart without downloading the older version of Dart and changing the environment variables manually?
I have gone through several StackOverflow posts and lot of Github issues without finding a proper solution.
Flutter lower dart version
Where is Dart's SDK located within /flutter folder?
Specifying SDK version in the pubspec.yaml does not seem to help.
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
Edit: Dart & Flutter support for Visual Studio Code docs says something about dart.sdkPaths and dart.flutterSdkPaths settings.
I had a similar problem:
My pubspec.yaml had the following:
environment:
sdk: ">=2.1.0 <3.0.0"
However when running flutter packages get I got the following error:
Running "flutter packages get" in xxx-app-mobile...
The current Dart SDK version is 2.1.0-dev.9.4.flutter-f9ebf21297.
Because xxx_app requires SDK version >=2.1.0 <3.0.0, version solving failed.
pub get failed (1)
I tried using the exact version name as the environment variable it did not work. I tried:
flutter upgrade
flutter clean
flutter update-packages
Received the same error when running flutter packages get
I then downgraded the version requirements in the pubspec.yaml to:
environment:
sdk: ">=2.0.0 <3.0.0"
And flutter packages get worked...
So I had an app that was developed on flutter 1.x SDK's, but after my completion, I moved on to build other projects and eventually shifted to fllutter2.0
As of now, flutter downgrade only lets you go one version back, Also going back from 2.x to 1.x seems difficult
So I went to this https://docs.flutter.dev/development/tools/sdk/releases site and downloaded the version i made the app in.
Then I had my dart-sdk for that specific project changed in Android Studio
Then I did the following
Deleted .idea folder and build folder as well as pubspec-lock file.
run flutter pub get
finally flutter build apk
Now this was a dire situation so I had to resort to this
I really will not recommend this unless you are in a rough spot
Simply update you flutter sdk to latest version.
First open your command (cmd) as an adminstrator then upgrade flutter : flutter upgrade it will do everything for you