bluetooth_print icon indicating copy to clipboard operation
bluetooth_print copied to clipboard

Unhandled Exception: type 'Null' is not a subtype of type 'FutureOr<int>'

Open jimmymchau opened this issue 1 year ago • 5 comments

I cant read the state of bluetooth if there is any connected device? I want to kniow if there is a connected device and return that device. But on state am getting this error; BluetoothPrint.state. (package:bluetooth_print/bluetooth_print.dart:64:60)

  /// Gets the current state of the Bluetooth module
  Stream<int> get state async* {
    yield await _channel.invokeMethod('state').then((s) => s);     //-----------line no 64

    yield* _stateChannel.receiveBroadcastStream().map((s) => s);
  }

` // Platform messages are asynchronous, so we initialize in an async method. Future initBluetooth() async { bluetoothPrint.startScan(timeout: Duration(seconds: 4));

bool? isConnected = await bluetoothPrint.isConnected;

bluetoothPrint.state.listen((state) {
  print('cur device status: $state');

  switch (state) {
    case BluetoothPrint.CONNECTED:
      setState(() {
        _connected = true;
        tips = 'connect success';
      });
      break;
    case BluetoothPrint.DISCONNECTED:
      setState(() {
        _connected = false;
        tips = 'disconnect success';
      });
      break;
    default:
      break;
  }
});

if (!mounted) return;

if(isConnected!) {
  setState(() {
    _connected=true;
  });
}

}`

jimmymchau avatar Aug 29 '22 11:08 jimmymchau

i'm getting this error only on iOS. Were you able to solve it?

theGowda avatar Aug 29 '22 12:08 theGowda

i'm getting this error only on iOS. Were you able to solve it?

No... Still straggling

jimmymchau avatar Aug 29 '22 14:08 jimmymchau

I used on

i'm getting this error only on iOS. Were you able to solve it?

No... Still straggling

I used this fork https://github.com/foresightmobile/bluetooth_print/tree/dev. Dev branch. Works fine

theGowda avatar Aug 29 '22 14:08 theGowda

this problem still exist on version 4.1.0, anyone solved this problem ? can't run example project it keeping this error 😞

YouSour avatar Oct 28 '22 07:10 YouSour

latest version , no problem.

YouSour avatar Nov 02 '22 06:11 YouSour