Skip to content

Commit

Permalink
APP-3318 - Fix sticky motor slider (#153)
Browse files Browse the repository at this point in the history
* change to setPower

* more changes

* more changes

* move setState calls to before async calls

* remove extra call
  • Loading branch information
clintpurser authored Dec 1, 2023
1 parent 089ab6f commit 49cb251
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/widgets/resources/motor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,31 @@ class _ViamMotorWidgetState extends State<ViamMotorWidget> {

Future<void> setPower(double power) async {
try {
await widget.motor.setPower(power);
setState(() {
this.power = power;
});
await widget.motor.setPower(power);
} catch (e) {
error = e as Error;
}
}

Future<void> stop() async {
try {
await widget.motor.stop();
setState(() {
power = 0;
});
await widget.motor.stop();

// Sometimes the motor does not honor the first Stop call
// So we wait a small amount of time and try again.
await Future.delayed(const Duration(milliseconds: 10));
if (await widget.motor.isMoving()) {
await widget.motor.stop();
setState(() {
power = 0;
});

await widget.motor.stop();
}
} catch (e) {
error = e as Error;
Expand Down

0 comments on commit 49cb251

Please sign in to comment.