diff --git a/example/lib/home/home.dart b/example/lib/home/home.dart index 8fc97bc..c9f92bb 100644 --- a/example/lib/home/home.dart +++ b/example/lib/home/home.dart @@ -21,6 +21,7 @@ class MyApp extends StatefulWidget { class _MyAppState extends State { final _bleDevices = []; + final _hiddenDevices = []; bool _isScanning = false; QueueType _queueType = QueueType.global; TextEditingController servicesFilterController = TextEditingController(); @@ -48,6 +49,11 @@ class _MyAppState extends State { UniversalBle.scanStream.listen((result) { // log(result.toString()); + // If device is already in hidden devices, skip + if (_hiddenDevices.any((e) => e.deviceId == result.deviceId)) { + // debugPrint("Skipping hidden device: ${result.deviceId}"); + return; + } int index = _bleDevices.indexWhere((e) => e.deviceId == result.deviceId); if (index == -1) { _bleDevices.add(result); @@ -251,6 +257,30 @@ class _MyAppState extends State { text: 'Scan Filters', onPressed: _showScanFilterBottomSheet, ), + if (_hiddenDevices.isNotEmpty) + PlatformButton( + text: 'Unhide ${_hiddenDevices.length} Devices', + onPressed: () { + setState(() { + _hiddenDevices.clear(); + }); + }, + ) + else if (_bleDevices.isNotEmpty) + Tooltip( + message: + 'Hide already discovered devices. When you turn on a new device, it will be easier to spot.', + child: PlatformButton( + text: 'Hide Already Discovered Devices', + onPressed: () { + setState(() { + _hiddenDevices.clear(); + _hiddenDevices.addAll(_bleDevices); + _bleDevices.clear(); + }); + }, + ), + ), if (_bleDevices.isNotEmpty) PlatformButton( text: 'Clear List',