TKeyValue.datetime constructor

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

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

Implementation

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