Nullable<T> class
A class that represents a nullable value It is used to wrap a value that can be null and provide a way to handle null values in a type-safe way Example in copyWith:
class Person {
final String name;
final int? age;
Person({required this.name, this.age});
Person copyWith({String? name, Nullable<int>? age}) {
return Person(name: name ?? this.name, age: age?.value ?? this.age);
}
}
final person = Person(name: "John", age: 30);
final personWithUnmodifiedAge = person.copyWith(age: null);
print(personWithUnmodifiedAge.age); // 30
final personWithModifiedAge = person.copyWith(age: Nullable(value: 40));
print(personWithModifiedAge.age); // 40
final personWithNullifiedAge = person.copyWith(age: Nullable(value: null));
print(personWithNullifiedAge.age); // null
Constructors
- Nullable({required T? value})
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- value → T?
-
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited