Recalibrate button works properly
This commit is contained in:
@@ -34,6 +34,7 @@ class _PeripheralScreenState extends State<PeripheralScreen> {
|
||||
String lastSetMessage = "";
|
||||
int? batterySoc;
|
||||
bool _movementPending = false;
|
||||
bool _awaitingDeviceWake = false;
|
||||
|
||||
final _peripheralRenameController = TextEditingController();
|
||||
|
||||
@@ -156,11 +157,14 @@ class _PeripheralScreenState extends State<PeripheralScreen> {
|
||||
if (data['periphID'] == widget.peripheralId) {
|
||||
if (!mounted) return;
|
||||
if (data['calibrated'] == false) {
|
||||
final wasAwaiting = _awaitingDeviceWake;
|
||||
setState(() {
|
||||
calibrated = false;
|
||||
calibrating = false;
|
||||
calibrationStage = 0;
|
||||
_awaitingDeviceWake = false;
|
||||
});
|
||||
if (wasAwaiting) calibrate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -504,7 +508,7 @@ class _PeripheralScreenState extends State<PeripheralScreen> {
|
||||
style: GoogleFonts.aBeeZee(),
|
||||
),
|
||||
content: const Text(
|
||||
"This will take under a minute",
|
||||
"After confirming, wake the device by moving the wand. Calibration will start automatically.",
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
actions: [
|
||||
@@ -517,15 +521,17 @@ class _PeripheralScreenState extends State<PeripheralScreen> {
|
||||
},
|
||||
child: const Text(
|
||||
"Cancel",
|
||||
style: TextStyle(
|
||||
color: Colors.red
|
||||
),
|
||||
style: TextStyle(color: Colors.red),
|
||||
)
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
calibrate();
|
||||
Navigator.of(dialogContext).pop();
|
||||
socket?.emit("recalibrate", {
|
||||
"periphID": widget.peripheralId,
|
||||
"periphNum": widget.peripheralNum,
|
||||
});
|
||||
setState(() => _awaitingDeviceWake = true);
|
||||
},
|
||||
child: const Text("Confirm")
|
||||
)
|
||||
@@ -610,7 +616,33 @@ class _PeripheralScreenState extends State<PeripheralScreen> {
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(child: loaded
|
||||
Expanded(child: _awaitingDeviceWake
|
||||
? Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
CircularProgressIndicator(color: Theme.of(context).primaryColorLight),
|
||||
const SizedBox(height: 24),
|
||||
Text(
|
||||
"Wake the device by moving the wand",
|
||||
style: GoogleFonts.aBeeZee(fontSize: 16),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
"Calibration will start automatically",
|
||||
style: GoogleFonts.aBeeZee(fontSize: 13, color: Colors.grey),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
TextButton(
|
||||
onPressed: () => setState(() => _awaitingDeviceWake = false),
|
||||
child: const Text("Cancel", style: TextStyle(color: Colors.red)),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: loaded
|
||||
? (calibrating
|
||||
? RefreshIndicator(
|
||||
onRefresh: initAll,
|
||||
@@ -770,9 +802,9 @@ class _PeripheralScreenState extends State<PeripheralScreen> {
|
||||
FloatingActionButton(
|
||||
heroTag: "recalibrate",
|
||||
tooltip: "Recalibrate Peripheral",
|
||||
onPressed: (deviceConnected && calibrated) ? recalibrate : null,
|
||||
foregroundColor: (deviceConnected && calibrated) ? Theme.of(context).highlightColor : Colors.grey.shade400,
|
||||
backgroundColor: (deviceConnected && calibrated) ? Theme.of(context).primaryColorDark : Colors.grey.shade300,
|
||||
onPressed: recalibrate,
|
||||
foregroundColor: Theme.of(context).highlightColor,
|
||||
backgroundColor: Theme.of(context).primaryColorDark,
|
||||
child: Icon(Icons.swap_vert),
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user