Skip to content

Commit

Permalink
fix: lock provider doesn't execute action if an action is pending
Browse files Browse the repository at this point in the history
  • Loading branch information
ses110 committed May 20, 2021
1 parent a02e68b commit 9a0c4e5
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions lib/providers/lock_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,25 @@ class LockProvider extends ChangeNotifier {
}

Future<void> setLockUnlockAction(String deviceId, bool setLock) async {
loadingAction = true;
if (!loadingAction) {
loadingAction = true;

notifyListeners();
notifyListeners();

await LockRepository.sendLockUnlockAction(_request, deviceId, setLock);
await LockRepository.sendLockUnlockAction(_request, deviceId, setLock);

var maxRetries = 0;
while (_deviceDetail?.traits?.first?.state?.value != setLock &&
maxRetries < 10) {
// Wait more time
_deviceDetail =
await DevicesRepository.getLockDetails(_request, deviceId);
await Future.delayed(Duration(milliseconds: 750));
maxRetries++;
}
loadingAction = false;
var maxRetries = 0;
while (_deviceDetail?.traits?.first?.state?.value != setLock &&
maxRetries < 10) {
// Wait more time
_deviceDetail =
await DevicesRepository.getLockDetails(_request, deviceId);
await Future.delayed(Duration(milliseconds: 750));
maxRetries++;
}
loadingAction = false;

notifyListeners();
notifyListeners();
}
}
}

0 comments on commit 9a0c4e5

Please sign in to comment.