Skip to content

Commit

Permalink
disable con mode toggle when gear disconnected
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed Dec 1, 2024
1 parent 866a54d commit c7a2654
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions lib/Frontend/Widgets/manage_gear.dart
Original file line number Diff line number Diff line change
Expand Up @@ -266,22 +266,27 @@ class ManageGearConventionMode extends ConsumerWidget {
ListTile(
title: Text(manageGearConModeToggleTitle()),
subtitle: Text("Upon enabling 'Convention Mode' your gear will be rebooted and you will be prompted to enter the pincode. Please view and memorize the pincode before enabling"),
trailing: Switch(
value: device.baseStoredDevice.conModeEnabled,
onChanged: (value) {
//reject if gear disconnected
if (value) {
BluetoothMessage bluetoothMessage = BluetoothMessage(message: "SETPUSSKEY ${device.baseStoredDevice.conModePin}", device: device, timestamp: DateTime.timestamp());
device.commandQueue.addCommand(bluetoothMessage);
device.baseStoredDevice.conModeEnabled = true;
ref.read(knownDevicesProvider.notifier).store();
} else {
BluetoothMessage bluetoothMessage = BluetoothMessage(message: "STOPPUSSKEY", device: device, timestamp: DateTime.timestamp());
device.commandQueue.addCommand(bluetoothMessage);
device.baseStoredDevice.conModeEnabled = false;
ref.read(knownDevicesProvider.notifier).store();
}
}),
trailing: ValueListenableBuilder(
valueListenable: device.deviceConnectionState,
builder: (context, connectivityState, child) => Switch(
value: device.baseStoredDevice.conModeEnabled,
onChanged: connectivityState == ConnectivityState.connected
? (value) {
//reject if gear disconnected
if (value) {
BluetoothMessage bluetoothMessage = BluetoothMessage(message: "SETPUSSKEY ${device.baseStoredDevice.conModePin}", device: device, timestamp: DateTime.timestamp());
device.commandQueue.addCommand(bluetoothMessage);
device.baseStoredDevice.conModeEnabled = true;
ref.read(knownDevicesProvider.notifier).store();
} else {
BluetoothMessage bluetoothMessage = BluetoothMessage(message: "STOPPUSSKEY", device: device, timestamp: DateTime.timestamp());
device.commandQueue.addCommand(bluetoothMessage);
device.baseStoredDevice.conModeEnabled = false;
ref.read(knownDevicesProvider.notifier).store();
}
}
: null),
),
),
OverflowBar(
children: [FilledButton(onPressed: () => PinCodeRoute(pin: device.baseStoredDevice.conModePin).push(context), child: Text(manageGearConModePincodeTitle()))],
Expand Down

0 comments on commit c7a2654

Please sign in to comment.