Flutter Migrate App to Null Safety | Flutter 2.0
Flutter cameup with new stable version flutter 2.0. This stable version supports null safety. What is null safety, means we no need to worry about null pointer exceptions while writing the flutter code, flutter will automatically checks null safety. This Null safety will make developer to create more reliable and secure programming code. In this post we are going to cover how to migrate existing flutter app to Null safety Let's get started Step 1: First step is to check is the project is migratable or not, because we can't migrate all projects Before start to migrate our app to Null safety first we need to check our installed flutter and dart versions to latest version First check the flutter version by below command flutter upgrade then hit enter, it will upgrade your version to latest version Then check your flutter and dart version Check dart latest version and download After verifying the flutter and dart version we need to check our dependency plugins are upto date to support null safety To do this type below command in terminal flutter pub outdated --mode=null-safety Now it will give the all your plugins with current and updates versions Now we can migrate our project to null safety feature We have done with 1st and 2nd steps, now it's time to migrate our project with 3rd step dart migrate Then if your packages are ready to, then the tool produce a link to check the migration suggestions View the migration suggestions by visiting: http://127.0.0.1:54269/D:/Blog%20Notes/Flutter/Workspace/sticky_header/sticky_header?authToken=3wM5xFgrgC8%3D Use this interactive web view to review, improve, or apply the results. If you make edits outside of the web view (in your IDE), use the 'Rerun from open that url in browser and check there every variable is defined with null safety For every variable and type annotation, we can see what nullability the tool infers in the update null safety code it added late for my varibale like below Now this exclmation mark tell that these vaibales can not have nullable values anymore Read more about Migration process at official page
We will Migrate flutter app to null safety by 3 simple steps
Step 2: We need to migrate our dependency plugins
Step 3: Call Migrate project
Make sure your flutter version to be 2.0 or above and take backup of your current flutter version and project
open command prompt or terminal and type command
Here all my versions are upto date except my url_launcher, now update this plugin version to latest version 5.7.10 by edit your pubspec.yaml file and change your version to 6.0.2 then get update version by run pub get command
Migrate app to null-safety type below command
When finished with the preview, hit ctrl-c to terminate this process.
sources' action.
late Map<String,List<Contact>>hm;
late List<String>alphabets;
List<Contact>namesString=hm[alphabets[index]]!
1332 Views