Complete Migration for Flutter App

Complete Migration for Flutter App


 In this tutorial you will learn to :

1-Set Up gradle environment after import project from git hub.
2-Migrate flutter app from V1 embedding to V2 embedding.
3-Migrate packages to support V2 embedding by two ways: [ manual & commends ].
4-Migrate your code from Sound Null Safety to Null Safety "flutter sdk 2.12.0" and later [ manual & commends ].


Migrate your code from Sound Null Safety to Null Safety "flutter sdk 2.12.0" and later








Requirement:
flutter sdk: 2.5 channel stable and later [ I work with flutter sdk: 2.10.5 channel stable ]

1-Set Up gradle environment after import project from git hub.

after download project from git hub, open zip file and open it from android studio and setup gradle and run pub get

2-Migrate flutter app from V1 embedding to V2 embedding.

see what is the errors in migrate app from V1 embedding to V2 embedding we have to errors

1-Your Flutter application is created using an older version of the Android
embedding.

that because we miss some steps to migrate app so we make sure about apple all the steps in the down link:

Steps of Upgrading pre 1 .12 Android projects to migrate flutter app to embedding v2

2-The plugins use a deprecated version of the Android embedding. try to see if these plugins support the Android V2 embedding.

that is mean flutter app migrated to V2 embedding successfully ,but some plugging version don't support V2 embedding so we need to change the version of plugging that not support

3-Migrate packages to support V2 embedding by two ways: [ manual & commends ].

To do that we have tow ways:

1- by hands :

change and choose the version of the plugins supportable with the V2 embedding and fix code's errors if there is.

2- by commands in terminal.

2.1- dart SDK 2.12 or later release of either the Dart SDK or the Flutter SDK:

$ dart --version

2.2- Get the migration state of your package’s dependencies:

$ dart pub outdated --mode=null-safety
# replacing any packages that not support Null safety ,if there is , with similar package that support it.

2.3- upgrade to the latest versions supporting null safety. Note: This command changes your pubspec.yaml file.

$ dart pub upgrade --null-safety

2.4- run following command:

$ dart pub get

2.5- fix code and run pub get again.

because our code is sound null safety ,it's better to migrate to null safety.

4-Migrate your code from Null Un-Safety to Null Safety "flutter sdk 2.12.0" and later.

There is tow ways to do that:

4.1-Migrating by hand, follow these steps:

4.1.1-Edit the package’s pubspec.yaml file, setting the minimum SDK constraint to at least 2.12.0:

4.1.2- Regenerate the package configuration file

$ dart pub get

4.1.3- Open the package in your IDE.

You’re likely to see a lot of analysis errors. try to fix it if there is.

4.1.4- Migrate the code of each Dart file, by adding ?, !, required, and late, as needed.

4.2-by using the migration tool

The migration tool takes a package of null-unsafe Dart code and converts it to null safety. Before starting the tool, make sure you’re ready:

4.2.1- Use the latest stable release of the Dart SDK.

4.2.2- using the following command to make sure that all dependencies are null safe and up-to-date.

$ dart pub outdated --mode=null-safety

4.2.3- Start the migration tool by running the following command in the directory that contains the package’s pubspec.yaml file:

$ dart migrate then the tool produces a special link for this project [click the link] to see what nullability the tool infers in the browser also you can see the reasons for each change (or non-change), click its line number in the Proposed Edits pane. The reasons appear in the Edit Details pane.

4.2.5- click migration button to applying Hint marker to your code and change flutter sdk version in pubspec.yaml to 2.12.0.

#every thing is done ^__^




ٌٌReference:

Migrating to null safety

Upgrading pre 1.12 Android projects

Supporting the new Android plugins APIs

Android v1 embedding app and plugin creation deprecation


تعليقات