0

I am building an app that searches for specific bluetooth devices. I am using FlutterBlue and so my code looks like this:

StreamBuilder<List<ScanResult>>(
    stream: FlutterBlue.instance.scanResults

The problem is that I want to filter out the results based on some criteria. scanResults is type Stream<List<ScanResult>> and with a normal List I would do .where((element) => true/false) but when I do .where the element is actually type List instead of the ScanResult which doesn't make sense.

Can't figure out how I am supposed to do this. I've searched around to no avail. I must be missing a setup to maintain the Stream but be able to rebuild the list based on a .where

1

1 Answer 1

1

To filter on the list you need to filter on the snapshot data provided in the StreamBuilder builder directly.

Here is a small example:

StreamBuilder<List<ScanResult>>(
  stream: FlutterBlue.instance.scanResults,
  builder: (_, snapshot) {
    if (!snapshot.hasData) {
      return LoadingWidget()
    }

    final filteredResult = snapshot.data!.where((element) => ...);
  },
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.