Featured Image
Software Development

How to Upgrade Flutter Version from 1.0 to 3.22

This blog post has been created with the intention of converting the project from Flutter version 1.22 to 3.22. 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.22. Before discussing the steps to update a Flutter project, let us explain why upgrading from Flutter 1.0 to 3.22 or Flutter 2.0 to 3.22 is essential.

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

For any developer or application owner, it is essential to upgrade Flutter to its latest version 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 in the future.

Here are some other benefits:

  • Latest Material3 theme support
  • Access to newly added widgets and their properties
  • Fast performance in the application due to improved engine performance
  • 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.22 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.22.0
/// Latest version is recommended
  • Update the Dart SDK version in a pubspec.yaml
sdk: ">=3.1.0 <4.0.0"

This will enable the Dart 3 SDK in your project, and after that, you can use all the new features of Dart 3, such as records, new class modifiers, exhaustiveness checking, if-case patterns, etc.

  • 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 below mentioned 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
  • Code migration to “Sound Null Safety” is required if your Dart SDK is outdated, specifically if it’s below version 2.12. Learn more about Sound null-safety.
  • Remove the following code  (found in much older versions) 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 26 OR (current minus 8) and targetSdkVersion to the latest one in app-level build.gradle.
    • Update the iOS deployment target version to 13.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, its 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.
  • Add the declarative plugins block from Flutter 3.22 and migrate those changes by following this guide.
"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/FirebaseAuth
    • 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.
  • Avoid using outdated versions of third-party packages/plugins, as they may cause issues with your current codebase.

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.

Are you ready to take your app to the next level with the latest Flutter upgrade? At Aubergine Solutions, we specialize in elevating your application’s performance through our expert Flutter development services. Our team ensures a smooth transition to the newest Flutter version, enhancing your app with advanced features and a seamless user experience. Contact us today.

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.