mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 17:47:28 +00:00
fix the issue in mobile to have indicator depend on time of unlock and unlock on pressing with lock animation
This commit is contained in:
@ -150,7 +150,6 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
|||||||
return super.close();
|
return super.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_doorLockUpdated(DoorLockUpdated event, Emitter<SmartDoorState> emit) {
|
_doorLockUpdated(DoorLockUpdated event, Emitter<SmartDoorState> emit) {
|
||||||
unlockRequest = deviceStatus.unlockRequest;
|
unlockRequest = deviceStatus.unlockRequest;
|
||||||
emit(UpdateState(smartDoorModel: deviceStatus));
|
emit(UpdateState(smartDoorModel: deviceStatus));
|
||||||
@ -254,7 +253,10 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _updateLock(UpdateLockEvent event, Emitter<SmartDoorState> emit) async {
|
void _updateLock(UpdateLockEvent event, Emitter<SmartDoorState> emit) async {
|
||||||
emit(LoadingNewSate(smartDoorModel: deviceStatus));
|
// emit(LoadingNewSate(smartDoorModel: deviceStatus));
|
||||||
|
final oldValue = deviceStatus.normalOpenSwitch;
|
||||||
|
deviceStatus = deviceStatus.copyWith(normalOpenSwitch: !oldValue);
|
||||||
|
emit(UpdateState(smartDoorModel: deviceStatus));
|
||||||
try {
|
try {
|
||||||
// final response = await DevicesAPI.controlDevice(
|
// final response = await DevicesAPI.controlDevice(
|
||||||
// DeviceControlModel(deviceId: deviceId, code: 'normal_open_switch', value: !event.value),
|
// DeviceControlModel(deviceId: deviceId, code: 'normal_open_switch', value: !event.value),
|
||||||
@ -262,10 +264,36 @@ class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
|||||||
|
|
||||||
final response = await DevicesAPI.openDoorLock(deviceId);
|
final response = await DevicesAPI.openDoorLock(deviceId);
|
||||||
|
|
||||||
if (response) {
|
if (!response) {
|
||||||
deviceStatus.normalOpenSwitch = !event.value;
|
_revertValueAndEmit(deviceId, 'normal_open_switch', oldValue, emit);
|
||||||
|
}
|
||||||
|
} catch (_) {
|
||||||
|
_revertValueAndEmit(deviceId, 'normal_open_switch', oldValue, emit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _revertValueAndEmit(String deviceId, String code, dynamic oldValue,
|
||||||
|
Emitter<SmartDoorState> emit) {
|
||||||
|
_updateLocalValue(code, oldValue);
|
||||||
|
emit(UpdateState(smartDoorModel: deviceStatus));
|
||||||
|
emit(const FailedState(errorMessage: 'Failed to control the device.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
void _updateLocalValue(String code, dynamic value) {
|
||||||
|
switch (code) {
|
||||||
|
case 'normal_open_switch':
|
||||||
|
if (value is bool) {
|
||||||
|
deviceStatus = deviceStatus.copyWith(normalOpenSwitch: value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'reverse_lock':
|
||||||
|
if (value is bool) {
|
||||||
|
deviceStatus = deviceStatus.copyWith(reverseLock: value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} catch (_) {}
|
|
||||||
emit(UpdateState(smartDoorModel: deviceStatus));
|
emit(UpdateState(smartDoorModel: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,4 +113,44 @@ class SmartDoorModel {
|
|||||||
remoteNoDpKey: _remoteNoDpKey,
|
remoteNoDpKey: _remoteNoDpKey,
|
||||||
normalOpenSwitch: _normalOpenSwitch);
|
normalOpenSwitch: _normalOpenSwitch);
|
||||||
}
|
}
|
||||||
|
SmartDoorModel copyWith({
|
||||||
|
String? uuid,
|
||||||
|
int? unlockFingerprint,
|
||||||
|
int? unlockPassword,
|
||||||
|
int? unlockTemporary,
|
||||||
|
int? unlockCard,
|
||||||
|
String? alarmLock,
|
||||||
|
int? unlockRequest,
|
||||||
|
int? residualElectricity,
|
||||||
|
bool? reverseLock,
|
||||||
|
int? unlockApp,
|
||||||
|
bool? hijack,
|
||||||
|
bool? doorbell,
|
||||||
|
String? unlockOfflinePd,
|
||||||
|
String? unlockOfflineClear,
|
||||||
|
String? unlockDoubleKit,
|
||||||
|
String? remoteNoPdSetkey,
|
||||||
|
String? remoteNoDpKey,
|
||||||
|
bool? normalOpenSwitch,
|
||||||
|
}) {
|
||||||
|
return SmartDoorModel(
|
||||||
|
unlockAlarm: alarmLock ?? unlockAlarm,
|
||||||
|
unlockFingerprint: unlockFingerprint ?? this.unlockFingerprint,
|
||||||
|
unlockPassword: unlockPassword ?? this.unlockPassword,
|
||||||
|
unlockTemporary: unlockTemporary ?? this.unlockTemporary,
|
||||||
|
unlockCard: unlockCard ?? this.unlockCard,
|
||||||
|
unlockRequest: unlockRequest ?? this.unlockRequest,
|
||||||
|
residualElectricity: residualElectricity ?? this.residualElectricity,
|
||||||
|
reverseLock: reverseLock ?? this.reverseLock,
|
||||||
|
unlockApp: unlockApp ?? this.unlockApp,
|
||||||
|
hijack: hijack ?? this.hijack,
|
||||||
|
doorbell: doorbell ?? this.doorbell,
|
||||||
|
unlockOfflinePd: unlockOfflinePd ?? this.unlockOfflinePd,
|
||||||
|
unlockOfflineClear: unlockOfflineClear ?? this.unlockOfflineClear,
|
||||||
|
unlockDoubleKit: unlockDoubleKit ?? this.unlockDoubleKit,
|
||||||
|
remoteNoPdSetkey: remoteNoPdSetkey ?? this.remoteNoPdSetkey,
|
||||||
|
remoteNoDpKey: remoteNoDpKey ?? this.remoteNoDpKey,
|
||||||
|
normalOpenSwitch: normalOpenSwitch ?? this.normalOpenSwitch,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import 'package:syncrow_app/generated/assets.dart';
|
|||||||
import 'package:syncrow_app/utils/context_extension.dart';
|
import 'package:syncrow_app/utils/context_extension.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
|
|
||||||
class DoorLockButton extends StatefulWidget {
|
class DoorLockButton extends StatelessWidget {
|
||||||
const DoorLockButton({
|
const DoorLockButton({
|
||||||
super.key,
|
super.key,
|
||||||
required this.doorLock,
|
required this.doorLock,
|
||||||
@ -18,157 +18,175 @@ class DoorLockButton extends StatefulWidget {
|
|||||||
|
|
||||||
final DeviceModel doorLock;
|
final DeviceModel doorLock;
|
||||||
final SmartDoorModel smartDoorModel;
|
final SmartDoorModel smartDoorModel;
|
||||||
@override
|
|
||||||
State<DoorLockButton> createState() => _DoorLockButtonState(smartDoorModel: smartDoorModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
class _DoorLockButtonState extends State<DoorLockButton> with SingleTickerProviderStateMixin {
|
double _calculateProgress() {
|
||||||
late AnimationController _animationController;
|
final value = smartDoorModel.unlockRequest;
|
||||||
late Animation<double> _animation;
|
if (value <= 0 || value > 30) return 0;
|
||||||
SmartDoorModel smartDoorModel;
|
return value / 30.0;
|
||||||
_DoorLockButtonState({required this.smartDoorModel});
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
|
|
||||||
_animationController = AnimationController(
|
|
||||||
vsync: this,
|
|
||||||
value: context.read<SmartDoorBloc>().unlockRequest > 0 ? 1 : 0,
|
|
||||||
duration: Duration(seconds: context.read<SmartDoorBloc>().unlockRequest),
|
|
||||||
);
|
|
||||||
if (context.read<SmartDoorBloc>().unlockRequest > 0) {
|
|
||||||
_animationController.reverse();
|
|
||||||
}
|
|
||||||
|
|
||||||
_animation = Tween<double>(begin: 0, end: 1).animate(_animationController)
|
|
||||||
..addListener(() {
|
|
||||||
setState(() {});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void didUpdateWidget(DoorLockButton oldWidget) {
|
|
||||||
super.didUpdateWidget(oldWidget);
|
|
||||||
|
|
||||||
if (_animationController.status == AnimationStatus.dismissed) {
|
|
||||||
if (context.read<SmartDoorBloc>().unlockRequest > 0) {
|
|
||||||
_animationController.value = 1;
|
|
||||||
_animationController.duration =
|
|
||||||
Duration(seconds: context.read<SmartDoorBloc>().unlockRequest);
|
|
||||||
_animationController.reverse();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
_animationController.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Padding(
|
final progress = _calculateProgress();
|
||||||
padding: EdgeInsets.only(
|
final isEnabled = smartDoorModel.unlockRequest > 0;
|
||||||
right: context.width * 0.25 / 2,
|
|
||||||
left: context.width * 0.25 / 2,
|
return SizedBox(
|
||||||
bottom: context.width * 0.2 / 2,
|
width: 255,
|
||||||
),
|
height: 255,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
overlayColor:
|
onTap: isEnabled
|
||||||
WidgetStateProperty.all(ColorsManager.primaryColorWithOpacity.withOpacity(0.1)),
|
? () {
|
||||||
borderRadius: BorderRadius.circular(999),
|
BlocProvider.of<SmartDoorBloc>(context).add(
|
||||||
onTapDown: (details) {
|
UpdateLockEvent(value: !smartDoorModel.normalOpenSwitch),
|
||||||
// if (_animationController.status == AnimationStatus.dismissed) {
|
);
|
||||||
// _animationController.forward();
|
|
||||||
// } else if (_animationController.status == AnimationStatus.completed) {
|
|
||||||
// _animationController.reverse();
|
|
||||||
// } else if (_animationController.status == AnimationStatus.forward) {
|
|
||||||
// _animationController.reverse();
|
|
||||||
// } else if (_animationController.status == AnimationStatus.reverse) {
|
|
||||||
// _animationController.forward();
|
|
||||||
// }
|
|
||||||
if (context.read<SmartDoorBloc>().unlockRequest > 0) {
|
|
||||||
BlocProvider.of<SmartDoorBloc>(context)
|
|
||||||
.add(UpdateLockEvent(value: smartDoorModel.normalOpenSwitch));
|
|
||||||
}
|
}
|
||||||
},
|
: null,
|
||||||
onTapUp: (details) {
|
|
||||||
// if (_animationController.status == AnimationStatus.forward) {
|
|
||||||
// _animationController.reverse();
|
|
||||||
// } else if (_animationController.status == AnimationStatus.reverse) {
|
|
||||||
// _animationController.forward();
|
|
||||||
// }
|
|
||||||
},
|
|
||||||
child: Container(
|
child: Container(
|
||||||
width: context.width * 06,
|
width: 255,
|
||||||
height: context.width * 0.6,
|
height: 255,
|
||||||
margin: const EdgeInsets.all(10),
|
decoration: BoxDecoration(
|
||||||
decoration: const BoxDecoration(
|
color: const Color(0xFFEBECED),
|
||||||
|
shape: BoxShape.circle,
|
||||||
boxShadow: [
|
boxShadow: [
|
||||||
BoxShadow(
|
BoxShadow(
|
||||||
color: Colors.grey,
|
color: Colors.grey.withOpacity(0.5),
|
||||||
blurRadius: 18,
|
blurRadius: 18,
|
||||||
// offset: Offset(6, 7),
|
|
||||||
blurStyle: BlurStyle.outer,
|
blurStyle: BlurStyle.outer,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
color: Color(0xFFEBECED),
|
|
||||||
borderRadius: BorderRadius.all(Radius.circular(999)),
|
|
||||||
),
|
),
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(25),
|
|
||||||
child: Stack(
|
child: Stack(
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
margin: const EdgeInsets.all(8),
|
margin: const EdgeInsets.all(30),
|
||||||
decoration: BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
color: Colors.white,
|
color: Color(0xFFF9F9F9),
|
||||||
borderRadius: BorderRadius.circular(999),
|
shape: BoxShape.circle,
|
||||||
boxShadow: [
|
|
||||||
BoxShadow(
|
|
||||||
color: Colors.white.withOpacity(0.5),
|
|
||||||
blurRadius: 30,
|
|
||||||
offset: const Offset(-5, -5),
|
|
||||||
blurStyle: BlurStyle.outer,
|
|
||||||
),
|
|
||||||
BoxShadow(
|
|
||||||
color: Colors.black.withOpacity(0.14),
|
|
||||||
blurRadius: 25,
|
|
||||||
offset: const Offset(5, 5),
|
|
||||||
blurStyle: BlurStyle.outer,
|
|
||||||
),
|
|
||||||
BoxShadow(
|
|
||||||
color: Colors.black.withOpacity(0.14),
|
|
||||||
blurRadius: 30,
|
|
||||||
offset: const Offset(5, 5),
|
|
||||||
blurStyle: BlurStyle.inner,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: SvgPicture.asset(
|
child: SvgPicture.asset(
|
||||||
smartDoorModel.normalOpenSwitch
|
smartDoorModel.normalOpenSwitch
|
||||||
? Assets.doorUnlockIcon
|
? Assets.doorUnlockIcon
|
||||||
: Assets.assetsIconsDoorlockAssetsLockIcon,
|
: Assets.assetsIconsDoorlockAssetsLockIcon,
|
||||||
|
width: 60,
|
||||||
|
height: 60,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox.expand(
|
if (progress > 0)
|
||||||
|
Container(
|
||||||
|
decoration: BoxDecoration(shape: BoxShape.circle),
|
||||||
|
height: 250,
|
||||||
|
width: 250,
|
||||||
child: CircularProgressIndicator(
|
child: CircularProgressIndicator(
|
||||||
value: _animation.value,
|
value: progress,
|
||||||
strokeWidth: 15,
|
strokeWidth: 8,
|
||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
valueColor: const AlwaysStoppedAnimation<Color>(ColorsManager.primaryColor),
|
valueColor: const AlwaysStoppedAnimation<Color>(
|
||||||
|
ColorsManager.primaryColor),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/door_lock/bloc/door_lock_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/door_lock/bloc/door_lock_event.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/door_lock/models/door_lock_status_model.dart';
|
||||||
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
|
|
||||||
|
class DoorLockButton extends StatelessWidget {
|
||||||
|
const DoorLockButton({
|
||||||
|
super.key,
|
||||||
|
required this.doorLock,
|
||||||
|
required this.smartDoorModel,
|
||||||
|
});
|
||||||
|
|
||||||
|
final DeviceModel doorLock;
|
||||||
|
final SmartDoorModel smartDoorModel;
|
||||||
|
|
||||||
|
double _calculateProgress() {
|
||||||
|
final value = smartDoorModel.unlockRequest;
|
||||||
|
if (value <= 0 || value > 30) return 0;
|
||||||
|
return value / 30.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final progress = _calculateProgress();
|
||||||
|
final isEnabled = smartDoorModel.unlockRequest > 0;
|
||||||
|
|
||||||
|
return SizedBox(
|
||||||
|
width: 255,
|
||||||
|
height: 255,
|
||||||
|
child: InkWell(
|
||||||
|
onTap: isEnabled
|
||||||
|
? () {
|
||||||
|
BlocProvider.of<DoorLockBloc>(context).add(
|
||||||
|
UpdateLockEvent(value: !smartDoorModel.normalOpenSwitch),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
child: Container(
|
||||||
|
width: 255,
|
||||||
|
height: 255,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: const Color(0xFFEBECED),
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.grey.withOpacity(0.5),
|
||||||
|
blurRadius: 18,
|
||||||
|
blurStyle: BlurStyle.outer,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Stack(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
margin: const EdgeInsets.all(30),
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
color: Color(0xFFF9F9F9),
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: SvgPicture.asset(
|
||||||
|
smartDoorModel.normalOpenSwitch
|
||||||
|
? Assets.doorUnlock
|
||||||
|
: Assets.lockIcon,
|
||||||
|
width: 60,
|
||||||
|
height: 60,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (progress > 0)
|
||||||
|
SizedBox.expand(
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
value: progress,
|
||||||
|
strokeWidth: 8,
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
valueColor: const AlwaysStoppedAnimation<Color>(
|
||||||
|
ColorsManager.primaryColor),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
Reference in New Issue
Block a user