detectionLine function

(dynamic, dynamic, String) detectionLine(
  1. dynamic l10n,
  2. DetectionStatus status,
  3. DateTime now,
  4. String locale,
)

What status says about the cat in one line, with its icon and colour.

Implementation

(IconData, Color?, String) detectionLine(
  AppLocalizations l10n,
  DetectionStatus status,
  DateTime now,
  String locale,
) {
  final lastSeen = status.lastSeen;
  if (status.inView) {
    // The open visit names what is there; "Cat / Dog in view" only when it does not.
    final open = status.recent.isNotEmpty && status.recent.first.stayed == null
        ? status.recent.first.what
        : null;
    final what = watchedLabel(
      open == null ? status.classes : <String>[open],
      locale.split(RegExp('[_-]')).first,
    );
    return (Icons.pets, Colors.green, l10n.detectionInView(what));
  }
  if (status.dark) {
    return (Icons.nights_stay, Colors.blueGrey, l10n.detectionTooDark);
  }
  if (lastSeen != null) {
    final when = formatLastSeen(lastSeen, now, locale);
    return (Icons.history, null, l10n.detectionLastSeen(when));
  }
  return (Icons.visibility_off_outlined, null, l10n.detectionNotSeenYet);
}