我正在制作一个基于蓝牙功能的应用程序,为了将用户重定向到正确的页面,我需要知道蓝牙是否打开。有人知道我如何使用Flutter Blue做到这一点吗?
发布于 2020-11-20 16:29:08
如果你使用的是颤动蓝,那么这应该是可行的。
MaterialApp(
color: Colors.white,
home: StreamBuilder<BluetoothState>(
stream: FlutterBlue.instance.state,
initialData: BluetoothState.unknown,
builder: (c, snapshot) {
final state = snapshot.data;
if (state == BluetoothState.on) {
return FindDevicesScreen();
}
return BluetoothOffScreen(state: state);
}),
);蓝牙的状态在FlutterBlue.instance.state流中更新,您可以使用此流轻松访问蓝牙的状态。仅供参考,为使此功能正常工作,您应该请求在任何设备上使用蓝牙的权限。
https://stackoverflow.com/questions/64917056
复制相似问题