TKeyValue.datetime constructor

TKeyValue.datetime(
  1. String key,
  2. dynamic value, {
  3. bool utc = true,
  4. Widget? icon,
  5. double? width,
  6. Alignment? alignment,
  7. double? minWidth,
  8. double? maxWidth,
})

Creates a key-value item for displaying a formatted date/time using TDateTimeText.

Implementation

factory TKeyValue.datetime(
  String key,
  dynamic value, {
  bool utc = true,
  Widget? icon,
  double? width,
  Alignment? alignment,
  double? minWidth,
  double? maxWidth,
}) {
  Widget? widget;
  String? valStr;
  DateTime? dateTime;
  if (value is DateTime) {
    dateTime = value;
    valStr = value.toIso8601String();
  } else if (value is String && !value.isNullOrBlank) {
    valStr = value;
    dateTime = utc ? TFormatter.parseUtcISO(value)?.toLocal() : DateTime.tryParse(value);
  }
  if (dateTime != null) {
    widget = TDateTimeText(dateTime: dateTime);
  }
  return TKeyValue(
    key,
    value: widget == null ? valStr : null,
    widget: widget,
    icon: icon,
    width: width,
    alignment: alignment,
    minWidth: minWidth,
    maxWidth: maxWidth,
  );
}