From 6e82ceed7772b4937b6fe92cdbf001666260c73a Mon Sep 17 00:00:00 2001 From: Rohit Sangwan Date: Thu, 13 Nov 2025 20:54:11 +0530 Subject: [PATCH] Add button to hide discovered devices in example app (#191) * Add button to hide discovered devices in example app * Resolve Ai Comments * Apply suggestion from @fotiDim * Add tooltip --------- Co-authored-by: Foti Dim --- example/lib/home/home.dart | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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',