Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 知道蓝牙是否开启,颤振蓝色_Flutter_Bluetooth - Fatal编程技术网

Flutter 知道蓝牙是否开启,颤振蓝色

Flutter 知道蓝牙是否开启,颤振蓝色,flutter,bluetooth,Flutter,Bluetooth,我正在制作一个基于蓝牙功能的应用程序,为了将用户重定向到正确的页面,我需要知道蓝牙是否开启。有人知道我如何使用Flutter Blue做到这一点吗?如果您使用的是Flutter Blue,那么这应该可以 MaterialApp( color: Colors.white, home: StreamBuilder<BluetoothState>( stream: FlutterBlue.instance.state, initialData: Blueto

我正在制作一个基于蓝牙功能的应用程序,为了将用户重定向到正确的页面,我需要知道蓝牙是否开启。有人知道我如何使用Flutter Blue做到这一点吗?

如果您使用的是Flutter Blue,那么这应该可以

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);
      }),
);
MaterialApp(
颜色:颜色,白色,
主页:StreamBuilder(
流:blue.instance.state,
initialData:BluetoothState.unknown,
生成器:(c,快照){
最终状态=snapshot.data;
if(state==BluetoothState.on){
返回FindDeviceScreen();
}
返回屏幕外的蓝牙(状态:状态);
}),
);
蓝牙的状态在
blue.instance.state流中更新
您可以使用此流轻松访问蓝牙的状态。

仅供参考,要使此功能正常工作,您应申请在任何设备上使用蓝牙的权限。

如果您使用的是Flatter blue,则此功能应正常工作

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);
      }),
);
MaterialApp(
颜色:颜色,白色,
主页:StreamBuilder(
流:blue.instance.state,
initialData:BluetoothState.unknown,
生成器:(c,快照){
最终状态=snapshot.data;
if(state==BluetoothState.on){
返回FindDeviceScreen();
}
返回屏幕外的蓝牙(状态:状态);
}),
);
蓝牙的状态在
blue.instance.state流中更新
您可以使用此流轻松访问蓝牙的状态。

仅供参考,要使此功能发挥作用,您应该申请在任何设备上使用蓝牙的权限。

向我们展示您迄今为止的尝试我实际解决了问题,结果我需要一个BlueoothState,以便知道它是否处于活动状态。向我们展示您迄今为止的尝试我实际解决了问题,事实证明,我需要一个BlueoothState,以便知道它是否处于活动状态,伙计,在你回复之前几分钟,我以完全相同的方式解决了它。我真的很感激,伙计,在你回复之前几分钟我就用同样的方式解决了。真的很感激