A wrapper around arbitrary data
T to indicate presence or absence
Values are commonly used in companions to distringuish between
For instance, consider a table with a nullable column with a non-nullable
CREATE TABLE orders ( priority INT DEFAULT 1 -- may be null if there's no assigned priority ); For inserts in Dart, there are three different scenarios for the `priority` column: - It may be set to `null`, overriding the default value - It may be absent, meaning that the default value should be used - It may be set to an `int` to override the default value
As you can see, a simple
int? does not provide enough information to
distinguish between the three cases. A
null value could mean that the
column is absent, or that it should explicitly be set to
For this reason, drift introduces the Value wrapper to make the
- Value(T value)
Create a (present) value by wrapping the
Create an absent value that will not be written into the database, the
default value or null will be used instead.
- Value.ofNullable(T? value)
Create a value that is absent if
nulland present if it's not.const
- hashCode → int
The hash code for this object.
- present → bool
Whether this Value wrapper contains a present value that should be
inserted or updated.
- runtimeType → Type
A representation of the runtime type of the object.
- value → T
If this value is present, contains the value to update or insert.