I wanna create a bluetooth app that can control my devices.
I use flutter_blue and modify its example.
(https://pub.dev/packages/flutter_blue)
I have successfully a litle by adding the following lines (from line 178)
(c) => CharacteristicTile(
characteristic: c,
onReadPressed: () => c.read(),
onWritePressed: () async {
List<int> value = await c.read();
if (value.toString() == "[1]"){
await c.write([0]);
}
else{
await c.write([1]);
}
await c.read();
},
`And I can toggle the light in my device by pressing in this button
But, I wanna create a specific button to toggle the light. As you can see I created a RaisedButton.
Although I have created a button, I do not know how to create a _toggle function for it? Probably pass some parameters to that function. I have tried many ways but it seems that I have not gone in the right direction
_turnOn(List<BluetoothService> services) async {
//List<BluetoothService> services = await device.discoverServices();
services.forEach((service) async {
// do something with service
var characteristics = service.characteristics;
for(BluetoothCharacteristic c in characteristics) {
List<int> value = await c.read();
print(value);
await c.write([1]);
}
});
}