39 lines
1002 B
Dart
39 lines
1002 B
Dart
import 'package:flutter/material.dart';
|
|
|
|
/// Display copy + color for maintenance `days_until_due` from the API.
|
|
class MaintenanceDueDisplay {
|
|
const MaintenanceDueDisplay({
|
|
required this.label,
|
|
required this.color,
|
|
});
|
|
|
|
final String label;
|
|
final Color color;
|
|
|
|
/// Green/neutral upcoming, amber due today, red overdue.
|
|
static MaintenanceDueDisplay? fromDaysUntilDue(int? daysUntilDue) {
|
|
if (daysUntilDue == null) return null;
|
|
|
|
if (daysUntilDue > 0) {
|
|
return MaintenanceDueDisplay(
|
|
label:
|
|
'Due in $daysUntilDue day${daysUntilDue == 1 ? '' : 's'}',
|
|
color: const Color(0xFF16A34A),
|
|
);
|
|
}
|
|
|
|
if (daysUntilDue == 0) {
|
|
return const MaintenanceDueDisplay(
|
|
label: 'Due today',
|
|
color: Color(0xFFD97706),
|
|
);
|
|
}
|
|
|
|
final overdueBy = daysUntilDue.abs();
|
|
return MaintenanceDueDisplay(
|
|
label: 'Overdue by $overdueBy day${overdueBy == 1 ? '' : 's'}',
|
|
color: const Color(0xFFDC2626),
|
|
);
|
|
}
|
|
}
|