File tree Expand file tree Collapse file tree 3 files changed +18
-5
lines changed Expand file tree Collapse file tree 3 files changed +18
-5
lines changed Original file line number Diff line number Diff line change 12
12
- Improve stack traces for errors happening on drift isolates (which includes
13
13
usages of ` NativeDatabase.createInBackground ` ).
14
14
- Don't cache ` EXPLAIN ` statements, avoiding schema locks.
15
+ - Deprecate ` Value.ofNullable ` in favor of ` Value.absentIfNull ` , which is more
16
+ explicit about its behavior and allows nullable types too.
15
17
- Migrate ` WasmDatabase ` to ` dart:js_interop ` and ` package:web ` .
16
18
17
19
## 2.15.0
Original file line number Diff line number Diff line change @@ -158,6 +158,7 @@ class Value<T> {
158
158
/// This constructor should only be used when [T] is not nullable. If [T] were
159
159
/// nullable, there wouldn't be a clear interpretation for a `null` [value] .
160
160
/// See the overall documentation on [Value] for details.
161
+ @Deprecated ('Use Value.absentIfNull instead' )
161
162
const Value .ofNullable (T ? value)
162
163
: assert (
163
164
value != null || null is ! T ,
@@ -167,6 +168,15 @@ class Value<T> {
167
168
_value = value,
168
169
present = value != null ;
169
170
171
+ /// Create a value that is absent if [value] is `null` and [present] if it's
172
+ /// not.
173
+ ///
174
+ /// The functionality is equiavalent to the following:
175
+ /// `x != null ? Value(x) : Value.absent()` .
176
+ const Value .absentIfNull (T ? value)
177
+ : _value = value,
178
+ present = value != null ;
179
+
170
180
@override
171
181
String toString () => present ? 'Value($value )' : 'Value.absent()' ;
172
182
Original file line number Diff line number Diff line change @@ -105,15 +105,16 @@ void main() {
105
105
expect (entry.toCompanion (true ), const PureDefaultsCompanion ());
106
106
});
107
107
108
- test ('nullable values cannot be used with nullOrAbsent ' , () {
108
+ test ('utilities to wrap nullable values ' , () {
109
109
expect (
110
- // ignore: prefer_const_constructors
110
+ // ignore: prefer_const_constructors, deprecated_member_use_from_same_package
111
111
() => Value <int ?>.ofNullable (null ),
112
112
throwsA (isA <AssertionError >()));
113
113
114
- expect (const Value <int >.ofNullable (null ).present, isFalse);
115
- expect (const Value <int ?>.ofNullable (12 ).present, isTrue);
116
- expect (const Value <int >.ofNullable (23 ).present, isTrue);
114
+ expect (const Value <int ?>.absentIfNull (null ).present, isFalse);
115
+ expect (const Value <int >.absentIfNull (null ).present, isFalse);
116
+ expect (const Value <int ?>.absentIfNull (12 ).present, isTrue);
117
+ expect (const Value <int >.absentIfNull (23 ).present, isTrue);
117
118
});
118
119
119
120
test ('companions support hash and equals' , () {
You can’t perform that action at this time.
0 commit comments