diff --git a/lib/screens/scan_tab.dart b/lib/screens/scan_tab.dart index a675d9f..cbbc557 100644 --- a/lib/screens/scan_tab.dart +++ b/lib/screens/scan_tab.dart @@ -14,11 +14,14 @@ class ScanTab extends StatefulWidget { class ScanTabState extends State { static const _activeCollectionPrefKey = 'active_collection_id'; + static const _duplicateCooldown = Duration(seconds: 2); bool _isBusy = false; List _collections = []; Collection? _selectedCollection; bool _loadingCollections = true; + String? _lastProcessedHwId; + DateTime? _lastProcessedAt; @override void initState() { @@ -285,6 +288,15 @@ class ScanTabState extends State { } Future _processHwId(String hwId) async { + final now = DateTime.now(); + if (_lastProcessedHwId == hwId && + _lastProcessedAt != null && + now.difference(_lastProcessedAt!) < _duplicateCooldown) { + return true; + } + _lastProcessedHwId = hwId; + _lastProcessedAt = now; + final collection = _selectedCollection; if (collection == null) return false;