Pablo Esparza
Pablo Esparza

Reputation: 1

FlutterBluePlusException user rejected

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.

Upvotes: 0

Views: 21

Answers (0)

Related Questions