0%
Null Safety — Chapter 12

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 ?., ??, ??=, !, and late appropriately.


12.0 — Chapter objectives

By the end of this chapter, you will be able to:

  • explain what null is 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 late for deferred initialization;
  • use late final for 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>? from List<int?>;
  • read a Map without crashing the program;
  • write nullable parameters, default values, and required parameters;
  • apply a best-practices checklist to a real project.

Comments

Comments are powered by GitHub Discussions

Sign in with GitHub to join the discussion

Link copied!