format method

String format({
  1. String dateFormat = DateTimeFormatsVN.dateOnly,
})

Formats the date value according to the specified format string.

Returns an empty string if the date value is null. Otherwise, uses the DateTime extension method to format the date according to the provided format pattern.

Parameters:

Returns: A formatted date string, or an empty string if the date is null.

Example:

final field = JsonDate('createdAt');
field.value = DateTime(2024, 8, 7);
print(field.format()); // "07/08/2024" (using default format)
print(field.format(dateFormat: 'yyyy-MM-dd')); // "2024-08-07"

Implementation

String format({
  String dateFormat = DateTimeFormatsVN.dateOnly,
}) {
  if (rawValue == null) {
    return "";
  }
  return value.format(dateFormat: dateFormat);
}