dueDateWidget method

dynamic dueDateWidget(
  1. dynamic context,
  2. dynamic task
)

Implementation

Widget dueDateWidget(BuildContext context, Task task) {
  TextStyle? textStyle = Theme.of(context).textTheme.labelMedium;
  DateTime? dueDate =
      task.dueDate() == null ? null : DateTime.parse(task.dueDate()!);

  if (dueDate == null) return const SizedBox.shrink();

  String? label;
  Color iconColor = Colors.white54;
  if (dueDate.isToday) {
    label = L10n.of(context).dueToday;
  } else if (dueDate.isTomorrow) {
    label = L10n.of(context).dueTomorrow;
  } else if (dueDate.isPast) {
    label = dueDate.timeago();
    iconColor = Theme.of(context).colorScheme.onSurface;
    textStyle = textStyle?.copyWith(
      color: Theme.of(context).colorScheme.error,
    );
  }
  final dateText =
      DateFormat(DateFormat.YEAR_MONTH_WEEKDAY_DAY).format(dueDate);

  return Row(
    children: [
      Icon(
        Icons.access_time,
        color: iconColor,
        size: 18,
      ),
      const SizedBox(width: 6),
      Text(
        label ?? L10n.of(context).due(dateText),
        style: textStyle,
      ),
    ],
  );
}