Chapter 12 — Null Safety
Part 1A — Learning Dart · Chapter 12 of 62 · 5 hours
Chapter 12 — Null Safety
Level: beginner / intermediate Estimated duration: 5 hours Prerequisites: Chapter 11 — Advanced OOP (
abstract,mixins,enums) What you'll be able to do by the end: write Dart code in which a missing value can no longer crash the program, by distinguishing nullable types from non-nullable types and using?.,??,??=,!, andlateappropriately.
12.0 — Chapter objectives
By the end of this chapter, you will be able to:
- explain what
nullis and why it has cost the industry so much; - distinguish a non-nullable type (
String) from a nullable type (String?); - read and understand compiler error messages related to null safety;
- use the safe access operator
?.; - use the fallback value operator
??; - use the conditional assignment operator
??=; - explain why the
!operator is a last resort; - use
latefor deferred initialization; - use
late finalfor a value written only once; - recognize and fix a
LateInitializationError; - understand type promotion (flow analysis);
- explain why promotion fails on a class field;
- fix this problem with an intermediate local variable;
- distinguish
List<int>?fromList<int?>; - read a
Mapwithout crashing the program; - write nullable parameters, default values, and
requiredparameters; - apply a best-practices checklist to a real project.
Comments
Comments are powered by GitHub Discussions
Sign in with GitHub to join the discussion