Dart Null Safety in Flutter
All Flutter versions since Flutter 2 support Sound Null Safety. Strange as it may seem at first, this is to help you as a developer! In this course, see how to use Dart Null Safety to your advantage, and build apps faster and more reliably. Use null aware operators, the new “late” and “required” keywords, and understand how to automatically migrate your older null unsafe code to the newer Flutter versions. By Simone Alessandria.
Who is this for?
Developers who want to understand and use Null Safety features in Flutter
- Nullable and Non-nullable types
- Late and Required
- Null-aware Operators
- Type Promotion
- Conditional Property Access
- Dart migrate
Part 1: Dart Null Safety in Flutter
Learn what Null Safety is, why it can simplify your life as a developer, and see how to declare and use both nullable and non-nullable types in a Dartpad window.
Still using DartPad, see how to leverage “Type Promotion”. Dart can parse your code and understand that in some cases you can use nullable variables just like non-nullable ones.
See how to create a class parsing JSON data, and understand when and how to use the “late” keyword in your fields, and the “required” decorator in your constructors.
Fix Null Errors
In an imperfect world, you sometimes retrieve imperfect data. In this episode, see how to deal with JSON data containing unexpected values, fixing a class that breaks when receiving null values. Also understand and use null-aware operators in your code.
Function parameters should also follow null safety rules. See how to pass nullable and non-nullable parameters to your functions, and how to deal with nullable data inside them.
In this episode, understand how to use the dart migrate command line tool to automatically upgrade your code to null safety. You will also see how to decide which parts of your project should be migrated, and how to annotate your code to guide the tool in making the best updates.