Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I upgrade an existing Flutter app?

Tags:

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.

  1. 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.

  2. 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?

like image 598
user1491884 Avatar asked Nov 12 '20 03:11

user1491884


People also ask

How do I update my Flutter manually?

You can update in android studio using Tools so follow these steps Android Studio -> Tools -> Flutter -> Flutter Upgrade. Save this answer. Show activity on this post.


3 Answers

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:

  1. Run flutter upgrade in the terminal to upgrade Flutter
  2. Run dart migrate to run the dart migration tool.
  3. Solve all errors which the migration tool shows.
  4. Run flutter pub outdated --mode=null-safety to print all outdated packages.
  5. Run flutter pub upgrade --null-safety to upgrade all packages automatically.
  6. Check the code for errors and solve them (Very important).
  7. Run dart migrate again and it should now be successful. Follow the link to checkout the proposed changes.
  8. Press the "Apply Migration" button.
  9. Check the code for errors again and fix them.

Your project should be updated now. Referenced from this website.

like image 193
Zacktamondo Avatar answered Oct 09 '22 14:10

Zacktamondo


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
like image 8
Chinmay Mourya Avatar answered Oct 09 '22 14:10

Chinmay Mourya


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
  1. Where version: 1.0.0+1 is your flutter app version
  2. When you run command flutter run your app should pick up the environment as defined which is sdk: ">=2.1.0 <3.0.0"
  3. 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
like image 3
Sunil Kumar Avatar answered Oct 09 '22 14:10

Sunil Kumar