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.
This commit is contained in:
rzuasti
2026-06-05 21:57:58 -04:00
parent 6b044a6739
commit 48d73fb207
22 changed files with 533 additions and 859 deletions
@@ -1,11 +1,13 @@
class ArpScannerStatus {
/// Status of an active scanner (one that runs on an interval, e.g. ARP, SNMP).
/// Mirrors the backend's `ActiveSnapshot` / `ActiveScannerStatusResponse`.
class ActiveScannerStatus {
final bool isRunning;
final double? runningForSeconds;
final double? nextRunInSeconds;
final int? lastScanDevicesSeen;
final double? lastScanSecondsAgo;
const ArpScannerStatus({
const ActiveScannerStatus({
required this.isRunning,
this.runningForSeconds,
this.nextRunInSeconds,
@@ -13,8 +15,8 @@ class ArpScannerStatus {
this.lastScanSecondsAgo,
});
factory ArpScannerStatus.fromJson(Map<String, dynamic> json) {
return ArpScannerStatus(
factory ActiveScannerStatus.fromJson(Map<String, dynamic> json) {
return ActiveScannerStatus(
isRunning: json['is_running'] as bool,
runningForSeconds: (json['running_for_seconds'] as num?)?.toDouble(),
nextRunInSeconds: (json['next_run_in_seconds'] as num?)?.toDouble(),
@@ -1,23 +0,0 @@
class DhcpScannerStatus {
final bool isListening;
final double? listeningForSeconds;
final int devicesSeen;
final double? lastDeviceSeenSecondsAgo;
const DhcpScannerStatus({
required this.isListening,
this.listeningForSeconds,
required this.devicesSeen,
this.lastDeviceSeenSecondsAgo,
});
factory DhcpScannerStatus.fromJson(Map<String, dynamic> json) {
return DhcpScannerStatus(
isListening: json['is_listening'] as bool,
listeningForSeconds: (json['listening_for_seconds'] as num?)?.toDouble(),
devicesSeen: (json['devices_seen'] as num).toInt(),
lastDeviceSeenSecondsAgo: (json['last_device_seen_seconds_ago'] as num?)
?.toDouble(),
);
}
}
@@ -1,23 +0,0 @@
class MdnsScannerStatus {
final bool isListening;
final double? listeningForSeconds;
final int devicesSeen;
final double? lastDeviceSeenSecondsAgo;
const MdnsScannerStatus({
required this.isListening,
this.listeningForSeconds,
required this.devicesSeen,
this.lastDeviceSeenSecondsAgo,
});
factory MdnsScannerStatus.fromJson(Map<String, dynamic> json) {
return MdnsScannerStatus(
isListening: json['is_listening'] as bool,
listeningForSeconds: (json['listening_for_seconds'] as num?)?.toDouble(),
devicesSeen: (json['devices_seen'] as num).toInt(),
lastDeviceSeenSecondsAgo: (json['last_device_seen_seconds_ago'] as num?)
?.toDouble(),
);
}
}
@@ -1,18 +1,20 @@
class SsdpScannerStatus {
/// Status of a passive scanner (one that listens continuously, e.g. mDNS, SSDP,
/// DHCP). Mirrors the backend's `PassiveSnapshot` / `PassiveScannerStatusResponse`.
class PassiveScannerStatus {
final bool isListening;
final double? listeningForSeconds;
final int devicesSeen;
final double? lastDeviceSeenSecondsAgo;
const SsdpScannerStatus({
const PassiveScannerStatus({
required this.isListening,
this.listeningForSeconds,
required this.devicesSeen,
this.lastDeviceSeenSecondsAgo,
});
factory SsdpScannerStatus.fromJson(Map<String, dynamic> json) {
return SsdpScannerStatus(
factory PassiveScannerStatus.fromJson(Map<String, dynamic> json) {
return PassiveScannerStatus(
isListening: json['is_listening'] as bool,
listeningForSeconds: (json['listening_for_seconds'] as num?)?.toDouble(),
devicesSeen: (json['devices_seen'] as num).toInt(),
@@ -1,25 +0,0 @@
class SnmpScannerStatus {
final bool isRunning;
final double? runningForSeconds;
final double? nextRunInSeconds;
final int? lastScanDevicesSeen;
final double? lastScanSecondsAgo;
const SnmpScannerStatus({
required this.isRunning,
this.runningForSeconds,
this.nextRunInSeconds,
this.lastScanDevicesSeen,
this.lastScanSecondsAgo,
});
factory SnmpScannerStatus.fromJson(Map<String, dynamic> json) {
return SnmpScannerStatus(
isRunning: json['is_running'] as bool,
runningForSeconds: (json['running_for_seconds'] as num?)?.toDouble(),
nextRunInSeconds: (json['next_run_in_seconds'] as num?)?.toDouble(),
lastScanDevicesSeen: (json['last_scan_devices_seen'] as num?)?.toInt(),
lastScanSecondsAgo: (json['last_scan_seconds_ago'] as num?)?.toDouble(),
);
}
}