Featured Image
Software Development

How to Upgrade Flutter Version from 1.0 to 3.13

This blog post has been created with the intention of converting the project from Flutter version 1.22 to 3.13. It has also been updated to reflect the latest information and changes related to upgrading Flutter versions. It is also helpful if you want to upgrade Flutter from 2.0 to 3.13. Before discussing the steps to update a Flutter project, let us explain why upgrading from Flutter 1.0 to 3.13 or Flutter 2.0 to 3.13 is essential.

Why Upgrade the Flutter Version for Your Old Project in 2024?

For any developer or application owner, it is essential to upgrade to Flutter 3.13 for the following reasons:

Firstly, Flutter is an ever-evolving framework and its latest version offers improved performance, security, and features. 

Secondly, upgrading the Flutter version will allow developers to take advantage of the latest features, such as improved animations, better UI/UX design, enhanced accessibility features, and more. This will help make the project more attractive and engaging for users.

Thirdly, upgrading the Flutter version will help ensure the project remains compatible with other platforms, such as iOS and Android. This is especially important for projects that are cross-platform compatible.

Finally, upgrading the Flutter version will ensure that the project remains up-to-date with industry trends and competitive with other projects. This will help ensure that the project is successful and remains relevant.

Here are some other benefits:

  • Firebase support and theme extensions
  • New web and mobile components
  • Faster iOS releases due to an improved refresh rate
  • International text input support and image decoding ability
  • Flutter Upgrade Package comprises the Flutter Casual Games Toolkit

Overall, upgrading the Flutter version of an old project in 2024 is a great idea that will help ensure the project remains competitive, attractive, and up-to-date. Also, when you upgrade Flutter to the latest version, your project can be prepared to support macOS and Linux as well. Therefore, the technology now supports six platforms.

Learn about some of the options for animating in Flutter.

How to Upgrade Flutter Project (Flutter 1 to 3.13 or v2 to v3)?

  • The latest Flutter should be installed in the system. If you do not have the latest Flutter SDK, then install it first. Here are the steps for Flutter installation.
  • If you have an older version of Flutter already installed, run the following command to upgrade Flutter.
flutter upgrade
fvm install stable

--------OR--------

fvm install 3.13.5
/// Latest version is recommended
  • Update the Dart SDK version in a pubspec.yaml
sdk: ">=3.0.0 <4.0.0"

This will enable the Dart3 SDK in your project, and after that, you can use all the new features of Dart3.

  • Run the following command
flutter pub get
  • After the above command, You will get errors related to third-party packages/plugins due to the non-supported Dart SDK version. Update those third-party packages/plugins to the latest version. The IDE plugin can help with this.
Version Lens – (VS code)Flutter pub version checker – (Android studio)
  • Run the flutter pub get command and fix the errors until you reach exit code 0
  • You will get syntax errors at most places due to ”Sound null-safety” and code updation with new versions. Update that code at every location as per null-safety supports.
  • Remove the following code from MainActivity.kt located at android/app/src/main/kotlin/**/**/MainActivity.kt
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
   GeneratedPluginRegistrant.registerWith(flutterEngine);
}

Do not remove method-channel code if you are using it for accessing platform-side code.

Learn about unleashing the power of Dart’s extension methods in Flutter to boost productivity.

  • Recommended platform settings to do:
    • Upgrading Android Studio and Xcode first is a recommended step.
    • Update minSdkVersion to at least 24 OR (current minus 8) and targetSdkVersion to the latest one in app-level build.gradle.
    • Update the iOS deployment target version to 12.0 from XCode. You can consider this to be (current minus 4).
  • Finally, it’s time to run the project. Run your project, and you may get errors related to platform-specific code and inside Flutter code as well.
  • For the Dart code, you should follow the official documentation for relevant changes.
  • For platform-specific code, you should follow the official documentation of that platform too.
  • Below are some usual errors that may happen to every project.

Android

  • You may need to add third-party dependencies at the app level build.gradle due to package updates in pubspec.yaml.
  • Over time, It’s mandatory to use the latest supported Gradle Version. For this, you need the following changes
  • Replace jcenter() to mavenCentral() inside repositories {} at project-level build.gradle. (You can find it at 2 places)
  • Update the Kotlin version ext.kotlin_version inside the project-level build.gradle (Check the latest version here)
  • Starting from Android SDK version 33, ‘compileSdkVersion‘ is deprecated. Therefore, replace it with ‘compileSdk‘ and always target and compile using the latest SDK version.
  • Remove the following implementation from the dependencies {} section in the app-level build.gradle file, as it is no longer required.
"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

Note: You can find suggestions in Android Studio for the Flutter update process. So, if you wish to upgrade to a specific version of Flutter not mentioned in this post, refer to Android Studio’s guides.

iOS

  • Minimum Xcode 14 is required to use Flutter version 3.13+
  • Run the following command to update the iOS pod.
pod repo update
  • If you have updated Firebase plugins then It may be required to update their pod manually. To do that follow the below commands for reference. Below are some examples.
    • To update firebase_core pod update Firebase/FirebaseCore
    • To update firebase_auth pod update Firebase/FirebaseCore
    • To update firebase_crashlytics pod update Firebase/FirebaseCrashlytics
  • If you have updated flutter_facebook_auth then run the command pod update FBSDKLoginKit

Note: You have these commands in the error logs when you run and encounter these types of errors.

Developers’ Guidelines on Upgrading Flutter

  • Always follow standard documentation when making any updates to Flutter/platform-specific.
  • Check for recommended Flutter updates to do or changes to make when you go to update the Flutter version.
  • For upgrading to the latest version from Flutter 2.0, 1.22 or any lower version, you can follow our guide. When you want to upgrade a pre-1.12 Flutter project, kindly follow this guideline for Android.

Migration guide to update Flutter code

  • You can find all the necessary changes for your deprecated code in the Flutter migration guide
  • It shows which code has been deprecated in which version and which deprecated code has been removed in which version.
author
Nayan Babariya
A Senior Flutter Engineer with specialization in the Flutter framework for building cross-platform mobile applications. I have a strong understanding of the Flutter ecosystem and am able to use its various features and tools to build high-quality, scalable, and maintainable apps.