| |
| |
| |
| # 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<int>? maybeList; |
| Map<String, String>? maybeMap; |
| |
| MyClass({this.maybeStr, this.maybeList, this.maybeMap}); |
| |
| MyClass cloneWithOverrides({ |
| OptionalNullable<String> maybeStr = const OptionalNullable.undefined(), |
| OptionalNullable<List<int>> maybeList = const OptionalNullable.undefined(), |
| OptionalNullable<Map<String, String>> 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) → 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) → 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) → 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) → 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>_ |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |