Flutter_blue: Provide API to check if BLE scan is in progress

Created on 29 Jul 2019  路  4Comments  路  Source: pauldemarco/flutter_blue

Internally _isScanning.value == true is used to check if BLE scan is in progress. Please provide API to do the same check in the app code

Most helpful comment

In my case I can't use StreamBuilder and need to check if scan initiated on a previous screen is running when user switched to the next screen

await FlutterBlue.instance.isScanning.first

It would be nice an easy if that worked. But that throws a stream state error when no scan is running. Besides, the library internally is using different code to check if scan is running. So, I'm asking to expose the same API to allow library consumers to use

All 4 comments

you can subscribe to "FlutterBlue.instance.isScanning" stream to get state / change in state .

Refer following code ( from flutter_blue example )

floatingActionButton: StreamBuilder<bool>(
        stream: FlutterBlue.instance.isScanning,
        initialData: false,
        builder: (c, snapshot) {
          if (snapshot.data) {
            return FloatingActionButton(
              child: Icon(Icons.stop),
              onPressed: () => FlutterBlue.instance.stopScan(),
              backgroundColor: Colors.red,
            );
          } else {
            return FloatingActionButton(
                child: Icon(Icons.search),
                onPressed: () => FlutterBlue.instance
                    .startScan(timeout: Duration(seconds: 8)));
          }
        },
      ),

In my case I can't use StreamBuilder and need to check if scan initiated on a previous screen is running when user switched to the next screen

In my case I can't use StreamBuilder and need to check if scan initiated on a previous screen is running when user switched to the next screen

await FlutterBlue.instance.isScanning.first

In my case I can't use StreamBuilder and need to check if scan initiated on a previous screen is running when user switched to the next screen

await FlutterBlue.instance.isScanning.first

It would be nice an easy if that worked. But that throws a stream state error when no scan is running. Besides, the library internally is using different code to check if scan is running. So, I'm asking to expose the same API to allow library consumers to use

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ekuleshov picture ekuleshov  路  3Comments

adamk22 picture adamk22  路  5Comments

Fleximex picture Fleximex  路  3Comments

ssaylanc picture ssaylanc  路  4Comments

FWeissenb picture FWeissenb  路  5Comments