There is no way to check if an argument is provided or not. The main reason for eliminating it was that it was very difficult to forward calls this way.
null " ". (, null ) . null, . null, :
foo([x = true, y]) => print("$x, $y");
foo(); // prints "true, null"
, , , :
class MyClass {
int x;
bool b;
MyClass(int x, [bool b]) {
if(b == null) { // treat as if not given.
// ...
}
}
}
new MyClass(5, null) new MyClass(5) . , :
class _Sentinel { const _Sentinel(); }
...
MyClass(int x, [b = const _Sentinel()]) {
if (b == const _Sentinel()) b = true;
...
}
, . b.