JsonDate class
A specialized JSON field for handling date and time values.
JsonDate extends JsonField<DateTime> to provide comprehensive date/time handling in JSON data. It supports parsing date strings, formatting dates for display, and serializing dates to ISO 8601 format in UTC.
Key Features:
- Automatic parsing of ISO 8601 date strings
- Defaults to current date/time when value is null
- Formats dates using customizable format strings
- Serializes dates to UTC ISO 8601 format for JSON
Usage Example:
final createdAt = JsonDate('createdAt');
createdAt.value = '2024-08-07T12:34:56Z'; // Parses string
createdAt.value = DateTime.now(); // Accepts DateTime directly
print(createdAt.format()); // Formatted string for display
print(createdAt.toJson()); // ISO 8601 UTC string for JSON
See also:
- JsonField for the base field implementation
- DateTimeFormatsVN for available date format constants
Properties
- error ↔ String?
-
An error message associated with this field, if any.
getter/setter pairinherited
- fieldName → String
-
The name of this field as it appears in JSON data.
finalinherited
- hasError → bool
-
Returns
trueif this field has an error message.no setterinherited - hashCode → int
-
Returns the hash code for this field.
no setterinherited
- hasInformation → bool
-
Returns
trueif this field has an informational message.no setterinherited - hasWarning → bool
-
Returns
trueif this field has a warning message.no setterinherited - information ↔ String?
-
An informational message associated with this field, if any.
getter/setter pairinherited
- isNotNull → bool
-
Returns
trueif the raw value of this field is notnull.no setterinherited - isNull → bool
-
Returns
trueif the raw value of this field isnull.no setterinherited - rawValue ↔ DateTime?
-
The raw, unprocessed value stored in this field.
getter/setter pairinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- value ↔ DateTime
-
Returns the DateTime value of this field.
getter/setter pairoverride
- warning ↔ String?
-
A warning message associated with this field, if any.
getter/setter pairinherited
Methods
-
format(
{String dateFormat = DateTimeFormatsVN.dateOnly}) → String - Formats the date value according to the specified format string.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toJson(
) → String? -
Serializes the date value to an ISO 8601 UTC string for JSON.
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
Determines whether this field is equal to another object.
inherited