Type promotion là khi Dart tự động thu hẹp kiểu của biến dựa trên luồng điều khiển.
- Nếu bạn có
String?và kiểm traif (name != null), trong khối đó Dart coinamelàStringnon-nullable mà không cần!. - Điều này xảy ra tự động với kiểm tra null,
ischecks, và toán tử logic, giúp giảm boilerplate.
Type promotion is when Dart narrows a variable's type based on control flow.
- If you have a nullable
String?and checkif (name != null), inside that block Dart treatsnameas non-nullableStringwithout needing!. - This happens automatically with null checks,
ischecks, and logical operators.