mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
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.
34 lines
993 B
Dart
34 lines
993 B
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
/// Mixin for [State]s that display continuously-updating elapsed-time text
|
|
/// (e.g. "Running for 3m 12s"). It runs a once-per-second timer that calls
|
|
/// [setState] so those labels stay current, and cancels it automatically on
|
|
/// dispose.
|
|
///
|
|
/// Call [startRebuildTicker] from `initState` (or when becoming visible) and
|
|
/// [stopRebuildTicker] when the widget is paused/hidden. Both are idempotent.
|
|
mixin PeriodicRebuild<T extends StatefulWidget> on State<T> {
|
|
Timer? _rebuildTicker;
|
|
|
|
/// Starts the per-second rebuild ticker if it isn't already running.
|
|
void startRebuildTicker() {
|
|
_rebuildTicker ??= Timer.periodic(const Duration(seconds: 1), (_) {
|
|
if (mounted) setState(() {});
|
|
});
|
|
}
|
|
|
|
/// Stops the per-second rebuild ticker.
|
|
void stopRebuildTicker() {
|
|
_rebuildTicker?.cancel();
|
|
_rebuildTicker = null;
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
stopRebuildTicker();
|
|
super.dispose();
|
|
}
|
|
}
|