NullableDate class

Represents a date with nullable components (year, month, day).

Useful for date input scenarios where individual date parts may be missing or incomplete. Can convert to DateTime when all parts are present.

Example:

final date = NullableDate(year: 2024, month: 1, day: 15);
print(date.nullableDate); // DateTime(2024, 1, 15)

Constructors

NullableDate({int? year, int? month, int? day})
Creates a NullableDate.

Properties

date DateTime
Converts to DateTime, using 1 for missing parts (month/day) to avoid year shift.
no setter
day int?
The day component (nullable).
final
hashCode int
The hash code for this object.
no setteroverride
month int?
The month component (nullable).
final
nullableDate DateTime?
Converts to DateTime only if all parts are present.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
year int?
The year component (nullable).
final

Methods

copyWith({ValueGetter<int?>? year, ValueGetter<int?>? month, ValueGetter<int?>? day}) NullableDate
Creates a copy with specified parts replaced.
getDateTime({int? defaultYear = 0, int? defaultMonth = 1, int? defaultDay = 1}) DateTime?
Converts to DateTime with default values if any part is null.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toMap() Map<DatePart, int>
Converts to a map of date parts.
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
override
operator [](DatePart part) int?
Retrieves the value of a specific date part.