最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

flutter - FlutterBluePlusException user rejected - Stack Overflow

programmeradmin5浏览0评论

I'm trying to activate bluetooth

await FlutterBluePlus.turnOn();     

but if the user rejected my application stops. I can't handle errors properly, and I don't understand why it doesn't throw them correctly.

Even though, in theory, I catch the error. "on FlutterBluePlusException catch (e){"

try {
      await FlutterBluePlus.turnOn();     
      setState(() {
            _isBluetoothOn = true;
            });
    } on FlutterBluePlusException catch (e){
        ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(content: Text('Error de Bluetooth: ${e.description}')),
      );
    }     catch (e) {
      setState(() {
            _isBluetoothOn = false;
            });
    } finally{
      _conectandoBluetooth = false;
    }

I don't know what I need to do to properly catch the errors.

发布评论

评论列表(0)

  1. 暂无评论