chore(scanner): add duplicate-ID cooldown for rapid scan stability
- Ignore repeated processing of the same HW ID within a short 2s window - Prevent duplicate dialogs/inserts during very fast repeated captures - Keep continuous scanner loop responsive while reducing accidental re-triggers
This commit is contained in:
parent
8469d556bb
commit
a93694728e
1 changed files with 12 additions and 0 deletions
|
|
@ -14,11 +14,14 @@ class ScanTab extends StatefulWidget {
|
|||
|
||||
class ScanTabState extends State<ScanTab> {
|
||||
static const _activeCollectionPrefKey = 'active_collection_id';
|
||||
static const _duplicateCooldown = Duration(seconds: 2);
|
||||
|
||||
bool _isBusy = false;
|
||||
List<Collection> _collections = [];
|
||||
Collection? _selectedCollection;
|
||||
bool _loadingCollections = true;
|
||||
String? _lastProcessedHwId;
|
||||
DateTime? _lastProcessedAt;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
|
@ -285,6 +288,15 @@ class ScanTabState extends State<ScanTab> {
|
|||
}
|
||||
|
||||
Future<bool> _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;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue