flutter_blue icon indicating copy to clipboard operation
flutter_blue copied to clipboard

How to clear "scanResults"

Open GauravPatni opened this issue 6 years ago • 5 comments

HI,

Is there any way to clear "scanResults" ?

It require when we disconnect device & goto connect screen again ,where we call 'FindDevicesScreen' then it shows old devices as snapshot.data of FlutterBlue.instance.scanResults stream gives the last result.

Note that while calling "scan" scanResults list get clears because it internally calls _scanResults.add(<ScanResult>[]);

GauravPatni avatar Aug 20 '19 11:08 GauravPatni

Maybe we can add a clearList() method to the class FlutterBlue. Or change the scan method:

Change

if (timeout != null) {
    killStreams.add(Observable.timer(null, timeout));
}

to

if (timeout != null) {
    killStreams.add(Observable.timer(clearList, timeout).listen(
        (clearList) {
            if (clearList)
            {
                _scanResults = BehaviorSubject.seeded([]);
            }
        }));
}

clearList being a boolean you can pass to the scan method.

Fleximex avatar Aug 20 '19 12:08 Fleximex

Or at least add a 'lastScanDate' timestamp to the device to be able to filter devices.

jeanmatthieud avatar Aug 20 '19 16:08 jeanmatthieud

Thanks for the reply . But is there any way to clear scan results without editing package internal code ? as it is difficult to maintain if package version updates....

GauravPatni avatar Aug 21 '19 04:08 GauravPatni

So is there an easy way to get the latest available device list? From my usage, when I keep scanning all the device, if I turn off my ble device and turn on it again, since it is not a new device, the listen callback function doesn't get invoked immediately, it looks wired.

928PJY avatar Oct 04 '20 06:10 928PJY

I know this is an old issue but any chance there is now a way to do this?? When I call repeatedly call startScan(timeout:X) I'm still using the listener from my original scan and it doesn't clear the results. I can't turn bluetooth off and on because I'm trying to maintain multiple connections. Any wizdom appreciated.

LipJ01 avatar Aug 24 '23 09:08 LipJ01