blob: 9a3d47e74f29c6ba7c9465c5e4529a58616f2a44 [file] [log] [blame] [view]
# OptionalNullable<T> class
<p>A wrapper type for optional values that may also be <code>null</code>. This generic
class can be used in argument lists for optional arguments. When called, the
argument state will be one of:</p>
<ul>
<li><code>undefined</code> - The caller did not provide a new value</li>
<li>Some(value) - The caller provided a new, non-<code>null</code> value</li>
<li>None() - The caller provided a <code>null</code> value</li>
</ul>
<p>A common usage is:</p>
<pre class="language-dart"><code class="language-dart">class MyClass {
String? maybeStr;
List&lt;int&gt;? maybeList;
Map&lt;String, String&gt;? maybeMap;
MyClass({this.maybeStr, this.maybeList, this.maybeMap});
MyClass cloneWithOverrides({
OptionalNullable&lt;String&gt; maybeStr = const OptionalNullable.undefined(),
OptionalNullable&lt;List&lt;int&gt;&gt; maybeList = const OptionalNullable.undefined(),
OptionalNullable&lt;Map&lt;String, String&gt;&gt; maybeMap = const OptionalNullable.undefined(),
}) {
return MyClass(
maybeStr: maybeStr.or(this.maybeStr),
maybeList: maybeList.or(this.maybeList),
maybeMap: maybeMap.or(this.maybeMap),
);
}
}
main() {
final orig = MyClass(
maybeStr: null,
maybeList: [1, 2, 3],
maybeMap: {'door': 'wood', 'window': 'glass'},
);
final mod = orig.cloneWithOverrides(
maybeStr: Some('a string'),
maybeMap: None(),
);
assert(mod.maybeStr == 'a string');
assert(mod.maybeList!.length == 3);
assert(mod.maybeMap == null);
}
</code></pre>
**Implementers**
- [None](../package-fidl_fidl/None-class.md)
- [Some](../package-fidl_fidl/Some-class.md)
## Constructors
[OptionalNullable.undefined](../package-fidl_fidl/OptionalNullable/OptionalNullable.undefined.md) ()
Initialize an <a href="../package-fidl_fidl/OptionalNullable-class.md">OptionalNullable</a> to an undefined state. The value of
an <a href="../package-fidl_fidl/OptionalNullable-class.md">OptionalNullable</a> is considered "undefined" until overridden by
assigning it to <a href="../package-fidl_fidl/Some-class.md">Some</a> or <a href="../package-fidl_fidl/None-class.md">None</a>. _const_
## Properties
##### [hashCode](../package-fidl_fidl/OptionalNullable/hashCode.md) &#8594; int
The hash code for this object.
_<span class="feature">read-only</span><span class="feature">inherited</span>_
##### [isDefined](../package-fidl_fidl/OptionalNullable/isDefined.md) &#8594; bool
True if the value is <a href="../package-fidl_fidl/Some-class.md">Some</a> or <a href="../package-fidl_fidl/None-class.md">None</a>.
_<span class="feature">read-only</span>_
##### [isUndefined](../package-fidl_fidl/OptionalNullable/isUndefined.md) &#8594; bool
True if the value is not <a href="../package-fidl_fidl/Some-class.md">Some</a> or <a href="../package-fidl_fidl/None-class.md">None</a>.
_<span class="feature">read-only</span>_
##### [runtimeType](../package-fidl_fidl/OptionalNullable/runtimeType.md) &#8594; Type
A representation of the runtime type of the object.
_<span class="feature">read-only</span><span class="feature">inherited</span>_
## Methods
##### [noSuchMethod](../package-fidl_fidl/OptionalNullable/noSuchMethod.md)(Invocation invocation) dynamic
Invoked when a non-existent method or property is accessed.
_<span class="feature">inherited</span>_
##### [or](../package-fidl_fidl/OptionalNullable/or.md)(T fallback) T
If the value is <a href="../package-fidl_fidl/Some-class.md">Some</a>, the value is returned. If <a href="../package-fidl_fidl/None-class.md">None</a>, <code>null</code> is
returned. Otherwise, the value <code>isUndefined</code>, in which case the given
<code>fallback</code> value is returned instead.
##### [toString](../package-fidl_fidl/OptionalNullable/toString.md)() String
A string representation of this object.
_<span class="feature">inherited</span>_
## Operators
##### [operator ==](../package-fidl_fidl/OptionalNullable/operator_equals.md)(Object other) bool
The equality operator.
_<span class="feature">inherited</span>_