diff --git a/lib/features/devices/bloc/smart_door_bloc/smart_door_bloc.dart b/lib/features/devices/bloc/smart_door_bloc/smart_door_bloc.dart index 75fbd86..236c623 100644 --- a/lib/features/devices/bloc/smart_door_bloc/smart_door_bloc.dart +++ b/lib/features/devices/bloc/smart_door_bloc/smart_door_bloc.dart @@ -54,6 +54,7 @@ class SmartDoorBloc extends Bloc { bool isStartEndTime = true; DateTime? startTime; DateTime? endTime; + int unlockRequest = 0; List? temporaryPasswords = []; List? oneTimePasswords = []; List? timeLimitPasswords = []; @@ -128,6 +129,7 @@ class SmartDoorBloc extends Bloc { } _doorLockUpdated(DoorLockUpdated event, Emitter emit) { + unlockRequest = deviceStatus.unlockRequest; emit(UpdateState(smartDoorModel: deviceStatus)); } diff --git a/lib/features/devices/view/widgets/smart_door/door_button.dart b/lib/features/devices/view/widgets/smart_door/door_button.dart index 5bae692..92e924d 100644 --- a/lib/features/devices/view/widgets/smart_door/door_button.dart +++ b/lib/features/devices/view/widgets/smart_door/door_button.dart @@ -31,47 +31,36 @@ class _DoorLockButtonState extends State with SingleTickerProvid @override void initState() { super.initState(); + _animationController = AnimationController( vsync: this, - value: smartDoorModel.unlockRequest > 0 ? 1 : 0, - duration: Duration(seconds: smartDoorModel.unlockRequest), + value: context.read().unlockRequest > 0 ? 1 : 0, + duration: Duration(seconds: context.read().unlockRequest), ); - if (smartDoorModel.unlockRequest > 0) { + if (context.read().unlockRequest > 0) { _animationController.reverse(); } _animation = Tween(begin: 0, end: 1).animate(_animationController) ..addListener(() { - // if (_animation.status == AnimationStatus.completed) { - // if (widget.doorLock.status - // .firstWhere((element) => element.code == 'normal_open_switch') - // .value != - // true) { - // DevicesCubit.getInstance().deviceControl( - // DeviceControlModel( - // deviceId: widget.doorLock.uuid, code: 'normal_open_switch', value: true), - // widget.doorLock.uuid ?? ""); - // } - // BlocProvider.of(context) - // .add(UpdateLockEvent(value: smartDoorModel.normalOpenSwitch)); - // _animationController.reverse(); - // } - // } else if (_animation.status == AnimationStatus.dismissed) { - // // if (widget.doorLock.status - // // .firstWhere((element) => element.code == 'normal_open_switch') - // // .value != - // // false) { - // DevicesCubit.getInstance().deviceControl( - // DeviceControlModel( - // deviceId: widget.doorLock.uuid, code: 'normal_open_switch', value: false), - // widget.doorLock.uuid ?? ""); - // // } - // _animationController.forward(); - // } setState(() {}); }); } + @override + void didUpdateWidget(DoorLockButton oldWidget) { + super.didUpdateWidget(oldWidget); + + if (_animationController.status == AnimationStatus.dismissed) { + if (context.read().unlockRequest > 0) { + _animationController.value = 1; + _animationController.duration = + Duration(seconds: context.read().unlockRequest); + _animationController.reverse(); + } + } + } + @override void dispose() { _animationController.dispose(); @@ -100,7 +89,7 @@ class _DoorLockButtonState extends State with SingleTickerProvid // } else if (_animationController.status == AnimationStatus.reverse) { // _animationController.forward(); // } - if (smartDoorModel.unlockRequest > 0) { + if (context.read().unlockRequest > 0) { BlocProvider.of(context) .add(UpdateLockEvent(value: smartDoorModel.normalOpenSwitch)); }