Files
oott/frontend/lib/widgets/polled_stale_indicator.dart
T
rzuasti 48d73fb207 Consolidate frontend scanner, pagination, and tick-timer duplication
Collapse the five scanner status models into two shared shapes,
ActiveScannerStatus and PassiveScannerStatus, mirroring the backend's
active/passive vocabulary. Replace the five near-identical per-scanner
detail card files with a single scanner_status_cards.dart (two shared
resolvers plus a config list), and rebuild the combined home card to
iterate a list of scanners with two shape resolvers instead of five
copy-pasted resolve methods.

Extract two reusable mixins:
- PeriodicRebuild: the shared once-a-second "rebuild to refresh elapsed
  text" timer used by the scanner cards and the stale indicator.
- PaginatedListState: the shared pagination state, page-size/page-count
  getters, cancel-token-aware fetch orchestration, and disposal used by
  the device and notification lists.

No behaviour change; ~900 lines removed. Tests and analyzer pass.
2026-06-05 21:57:58 -04:00

52 lines
1.5 KiB
Dart

import 'package:flutter/material.dart';
import '../utils/backend_reachability.dart';
import '../utils/duration_formatter.dart';
import '../utils/periodic_rebuild.dart';
import '../utils/polled_value.dart';
class PolledStaleIndicator extends StatefulWidget {
const PolledStaleIndicator({super.key, required this.polled});
final PolledValue polled;
@override
State<PolledStaleIndicator> createState() => _PolledStaleIndicatorState();
}
class _PolledStaleIndicatorState extends State<PolledStaleIndicator>
with PeriodicRebuild<PolledStaleIndicator> {
@override
void initState() {
super.initState();
startRebuildTicker();
}
@override
Widget build(BuildContext context) {
final lastSuccessAt = widget.polled.lastSuccessAt;
final ago = lastSuccessAt != null
? formatSeconds(
DateTime.now().difference(lastSuccessAt).inSeconds.toDouble(),
)
: 'a while';
final isOffline = !BackendReachability.instance.isOnline;
final String message;
if (isOffline) {
message = 'Offline — last updated $ago ago';
} else if (widget.polled.lastErrorMessage != null) {
message = 'Last updated $ago ago — ${widget.polled.lastErrorMessage}';
} else {
message = 'Last updated $ago ago';
}
return Tooltip(
message: message,
child: Icon(
Icons.warning_amber_rounded,
size: 14,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
);
}
}