I have this error and i can't understand where is my mistake
[ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: NoSuchMethodError: The getter 'output' was called on null. E/flutter (16491): Receiver: null E/flutter (16491): Tried calling: output
the error refer to this function but i have no error syntax on it
import 'dart:convert';
BluetoothConnection connection;
void _sendOnMessageToBluetooth() async {
connection.output.add(utf8.encode("1" + "\r\n"));
await connection.output.allSent;
setState(() {
deviceState = 1;
});
}
and this is where i'am calling it
FlatButton(
onPressed: _sendOnMessageToBluetooth ==null? "": _sendOnMessageToBluetooth,
child:Text("ON",
style:TextStyle(color:Colors.red[400]),,),
can any one help !
connectionvariable? Where is it initialized in the code? - Jigar Patelconnectionand not initialized it. Have you assigned an instance ofBluetoothConnectionto it anywhere in the code? Something likeconnection = BluetoothConnection()? - Jigar Patel