Comments (10)
ah ok I see what is the issue now. You execute a stream subscription at the on build which I would try to avoid. It looks like a race condition on the Android layer. I would suggest to look to our example app. We execute the startscan on onTap but maintaining the subscription is done outside the build method. A simple solution can already be:
class Screen extends StatefulWidget {
Screen();
@override
_ScreenState createState() => _ScreenState();
}
class _ScreenState extends State<Screen> {
FlutterReactiveBle _ble = FlutterReactiveBle();
void startScan() {
_ble.scanForDevices(withServices: [], scanMode: ScanMode.lowPower, requireLocationServicesEnabled: true).listen((event) {
print(event.id);
}).onError((handleError) {
print(handleError);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: [
RaisedButton(
onPressed: startScan,
child: Text("Scan"),
),
],
),
),
);
}
}
Also check our example app for a even cleaner approach
from flutter_reactive_ble.
Hi, I've tried the code that you sent me and I'm still getting the same error.
I've noticed that if I move from compileSDK 30 to 28 it works.
from flutter_reactive_ble.
That is intended. Before scanning you need to make sure that the status of your ble is set to Ready
. See ble_status_monitor
in the example app for a simple implementation. We do not handle automatic asking for permissions since it is up to the user to decide how they want to handle it. For example https://pub.dev/packages/permission_handler provides a good way of handling this.
from flutter_reactive_ble.
@Errichamonda thanks for reporting the issue. Can you supply me the code that you are using for calling the scanForDevices
? Make sure that the parameter withServices
has a value as documented in the code.
from flutter_reactive_ble.
It's a simple Stateful Widget.
Permission are granted to localization to always.
I've also tried to give the withServices
parameter a List with one Uuid inside but I still got the same error.
class Screen extends StatefulWidget {
Screen();
@override
_ScreenState createState() => _ScreenState();
}
class _ScreenState extends State<Screen> {
FlutterReactiveBle _ble = FlutterReactiveBle();
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: [
RaisedButton(
onPressed: () {
_ble.scanForDevices(withServices: [], scanMode: ScanMode.lowPower, requireLocationServicesEnabled: true).listen((event) {
print(event.id);
}).onError((handleError) {
print(handleError);
});
},
child: Text("Scan"),
),
],
),
),
);
}
}
from flutter_reactive_ble.
That is very interesting... I updated the example app to compileSDK 30 and I have no issues. I use the exact same code as what I explained above and it works without raising an issue. I tested it both on Samsung and a google pixel as wel a galaxy tab. What I am thinking is it could be a device specific issue. Are you in the position of testing it on another android device? Also which version of Flutter are you using? I am using , v1.17.3
from flutter_reactive_ble.
Flutter (Channel beta, 1.19.0-4.3.pre, on Microsoft Windows [Versione 10.0.19041.329], locale it-IT)
• Flutter version 1.19.0-4.3.pre at C:\flutter
• Framework revision 8fe7655ed2 (12 days ago), 2020-07-01 14:31:18 -0700
• Engine revision 9a28c3bcf4
• Dart version 2.9.0 (build 2.9.0-14.1.beta)
I've tested on a OnePlus 6 with compileSDK 30 and it seems to work. Maybe it's something about Xiaomi software that causes the error. If I still encounter this error I'll reopen this issue. Thanks for the help.
Edit: it seems to be working properly now on Xiaomi device with compileSDK 30. I don't know what caused the issue.
from flutter_reactive_ble.
Hi, I'm having pretty much the same issue here. I was using a provider/get_it/mvvm architecture but I simplified it to the same code snipped shared above. I'm on Flutter 1.17.5 (the current stable).
I've tried this on 3 different Android devices, but no luck.
Here are my observations :
- If I leave the permission off (using the exact same code as above), the first button press says no location, the second button press says scanning parameters are not set
- If explicitly go to the app info and give it location permission, it works like a charm
- Even the example app compiled on my device throws the error in the image attached :
Help?
from flutter_reactive_ble.
@omarkamal we require location permissions since this is the safest way of scanning. You can avoid this requirement by:
_ble.scanForDevices(withServices: serviceIds, requireLocationServicesEnabled: false)
but this is at your own risk since Nexus devices need location services for scanning. I will reopen the issue because I am curious what happens on the second tap
from flutter_reactive_ble.
Hey, thanks for your response!
But that's the odd thing I noticed - even when I didn't explicitly set that flag, it never asked me for the location permission.
It was denied by default and I had to open app info and allow permissions there. Even setting the Bluetooth permissions on the project's own androidManifest didn't throw up a location prompt.
Tried this on a pixel 2 xl and an mi a2 both on Android 10.
I'll dig into the double button press a bit more to make sure it's nothing silly I'm doing on my end!
from flutter_reactive_ble.
Related Issues (20)
- Clone Example App not running HOT 1
- App crash - exception could not be delivered HOT 1
- Demo App for nRF52 DK UART HOT 2
- Cant connect after bluetooth is off/on HOT 1
- Choose between notifications or indications HOT 1
- No response value for long commands.
- OBD2 protocol connecton HOT 1
- Crash on permission change HOT 1
- 'readRssi' Method Not Defined for 'ReactiveBlePlatform' HOT 6
- protobuf ^3.1.0 support HOT 2
- scanForDevices should not use 'assert(!central.isScanning)' HOT 2
- A problem occurred evaluating project ':reactive_ble_mobile'. HOT 3
- 我编译遇到了下面的报错
- compileSdkVersion is not specified HOT 2
- How to connect with duplicate UUID characteristics via flutter_reactive_ble? HOT 1
- iOS connectToDevice() after finding device ID fails with PlatformException HOT 1
- Intermittent Read Failure Leading to Automatic Disconnection with flutter_reactive_ble HOT 1
- The BLE app does not disconnect immediately but only after smartphone locked HOT 1
- reactive ble is not wroking scan mode in ios release mode HOT 1
- Write issue on Nordic UART BLE HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter_reactive_ble.