mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-27 23:44:55 +00:00
Added smart door bloc
This commit is contained in:
@ -1,26 +1,21 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_event.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_state.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/smart_door_bloc/smart_door_event.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/smart_door_bloc/smart_door_state.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/smart_door.dart';
|
||||
import 'package:syncrow_app/features/devices/model/smart_door_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/three_gang_model.dart';
|
||||
import 'package:syncrow_app/services/api/devices_api.dart';
|
||||
|
||||
class SmartDoorBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
class SmartDoorBloc extends Bloc<SmartDoorEvent, SmartDoorState> {
|
||||
final String deviceId;
|
||||
late SmartDoorModel deviceStatus;
|
||||
|
||||
SmartDoorBloc({required this.deviceId}) : super(InitialState()) {
|
||||
on<InitialEvent>(_fetchThreeGangStatus);
|
||||
on<ChangeFirstSwitchStatusEvent>(_changeFirstSwitch);
|
||||
on<ChangeSecondSwitchStatusEvent>(_changeSecondSwitch);
|
||||
on<ChangeThirdSwitchStatusEvent>(_changeThirdSwitch);
|
||||
on<AllOffEvent>(_allOff);
|
||||
on<AllOnEvent>(_allOn);
|
||||
on<InitialEvent>(_fetchSmartDoorStatus);
|
||||
on<UpdateLockEvent>(_updateLock);
|
||||
}
|
||||
|
||||
void _fetchThreeGangStatus(InitialEvent event, Emitter<ThreeGangState> emit) async {
|
||||
void _fetchSmartDoorStatus(InitialEvent event, Emitter<SmartDoorState> emit) async {
|
||||
emit(LoadingInitialState());
|
||||
try {
|
||||
var response = await DevicesAPI.getDeviceStatus(deviceId);
|
||||
@ -29,94 +24,24 @@ class SmartDoorBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
statusModelList.add(StatusModel.fromJson(status));
|
||||
}
|
||||
deviceStatus = SmartDoorModel.fromJson(statusModelList);
|
||||
emit(UpdateState(threeGangModel: deviceStatus));
|
||||
emit(UpdateState(smartDoorModel: deviceStatus));
|
||||
} catch (e) {
|
||||
emit(FailedState(error: e.toString()));
|
||||
emit(FailedState(errorMessage: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void _changeFirstSwitch(ChangeFirstSwitchStatusEvent event, Emitter<ThreeGangState> emit) async {
|
||||
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
||||
void _updateLock(UpdateLockEvent event, Emitter<SmartDoorState> emit) async {
|
||||
emit(LoadingNewSate(smartDoorModel: deviceStatus));
|
||||
try {
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: deviceId, code: 'switch_1', value: !event.value), deviceId);
|
||||
DeviceControlModel(deviceId: deviceId, code: 'normal_open_switch', value: !event.value),
|
||||
deviceId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
deviceStatus.firstSwitch = !event.value;
|
||||
deviceStatus.normalOpenSwitch = !event.value;
|
||||
}
|
||||
} catch (_) {}
|
||||
emit(UpdateState(threeGangModel: deviceStatus));
|
||||
}
|
||||
|
||||
void _changeSecondSwitch(
|
||||
ChangeSecondSwitchStatusEvent event, Emitter<ThreeGangState> emit) async {
|
||||
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
||||
try {
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: deviceId, code: 'switch_2', value: !event.value), deviceId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
deviceStatus.secondSwitch = !event.value;
|
||||
}
|
||||
} catch (_) {}
|
||||
emit(UpdateState(threeGangModel: deviceStatus));
|
||||
}
|
||||
|
||||
void _changeThirdSwitch(ChangeThirdSwitchStatusEvent event, Emitter<ThreeGangState> emit) async {
|
||||
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
||||
try {
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: deviceId, code: 'switch_3', value: !event.value), deviceId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
deviceStatus.thirdSwitch = !event.value;
|
||||
}
|
||||
} catch (_) {}
|
||||
emit(UpdateState(threeGangModel: deviceStatus));
|
||||
}
|
||||
|
||||
void _allOff(AllOffEvent event, Emitter<ThreeGangState> emit) async {
|
||||
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
||||
|
||||
try {
|
||||
final response = await Future.wait([
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: deviceId, code: 'switch_1', value: false), deviceId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: deviceId, code: 'switch_2', value: false), deviceId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: deviceId, code: 'switch_3', value: false), deviceId),
|
||||
]);
|
||||
|
||||
if (response.every((element) => element['success'] ?? false)) {
|
||||
deviceStatus.firstSwitch = false;
|
||||
deviceStatus.secondSwitch = false;
|
||||
deviceStatus.thirdSwitch = false;
|
||||
}
|
||||
} catch (_) {}
|
||||
emit(UpdateState(threeGangModel: deviceStatus));
|
||||
}
|
||||
|
||||
void _allOn(AllOnEvent event, Emitter<ThreeGangState> emit) async {
|
||||
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
||||
|
||||
try {
|
||||
final response = await Future.wait([
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: deviceId, code: 'switch_1', value: true), deviceId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: deviceId, code: 'switch_2', value: true), deviceId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: deviceId, code: 'switch_3', value: true), deviceId),
|
||||
]);
|
||||
|
||||
if (response.every((element) => element['success'] ?? false)) {
|
||||
deviceStatus.firstSwitch = true;
|
||||
deviceStatus.secondSwitch = true;
|
||||
deviceStatus.thirdSwitch = true;
|
||||
}
|
||||
} catch (_) {}
|
||||
emit(UpdateState(threeGangModel: deviceStatus));
|
||||
emit(UpdateState(smartDoorModel: deviceStatus));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:syncrow_app/features/devices/model/smart_door.dart';
|
||||
import 'package:syncrow_app/features/devices/model/three_gang_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/smart_door_model.dart';
|
||||
|
||||
class SmartDoorState extends Equatable {
|
||||
const SmartDoorState();
|
||||
@ -30,10 +29,10 @@ class LoadingNewSate extends SmartDoorState {
|
||||
}
|
||||
|
||||
class FailedState extends SmartDoorState {
|
||||
final String error;
|
||||
final String errorMessage;
|
||||
|
||||
const FailedState({required this.error});
|
||||
const FailedState({required this.errorMessage});
|
||||
|
||||
@override
|
||||
List<Object> get props => [error];
|
||||
List<Object> get props => [errorMessage];
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
||||
|
||||
class SmartDoorModel {
|
||||
String unlockFingerprint;
|
||||
int unlockFingerprint;
|
||||
int unlockPassword;
|
||||
int unlockTemporary;
|
||||
int unlockCard;
|
||||
@ -39,7 +39,7 @@ class SmartDoorModel {
|
||||
required this.normalOpenSwitch});
|
||||
|
||||
factory SmartDoorModel.fromJson(List<StatusModel> jsonList) {
|
||||
late String _unlockFingerprint;
|
||||
late int _unlockFingerprint;
|
||||
late int _unlockPassword;
|
||||
late int _unlockTemporary;
|
||||
late int _unlockCard;
|
||||
@ -59,7 +59,7 @@ class SmartDoorModel {
|
||||
|
||||
for (int i = 0; i < jsonList.length; i++) {
|
||||
if (jsonList[i].code == 'unlock_fingerprint') {
|
||||
_unlockFingerprint = jsonList[i].value ?? '';
|
||||
_unlockFingerprint = jsonList[i].value ?? 0;
|
||||
} else if (jsonList[i].code == 'unlock_password') {
|
||||
_unlockPassword = jsonList[i].value ?? 0;
|
||||
} else if (jsonList[i].code == 'unlock_temporary') {
|
||||
@ -1,5 +1,4 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/display_medium.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
@ -110,7 +110,11 @@ void showDeviceInterface(DeviceModel device, BuildContext context) {
|
||||
case DeviceType.Blind:
|
||||
break;
|
||||
case DeviceType.DoorLock:
|
||||
navigateToInterface(DoorInterface(doorlock: device), context);
|
||||
Navigator.push(
|
||||
context,
|
||||
PageRouteBuilder(
|
||||
pageBuilder: (context, animation1, animation2) => DoorInterface(doorLock: device)));
|
||||
// navigateToInterface(DoorInterface(doorlock: device), context);
|
||||
break;
|
||||
case DeviceType.Gateway:
|
||||
break;
|
||||
|
||||
@ -1,9 +1,14 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_event.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/smart_door_bloc/smart_door_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/smart_door_bloc/smart_door_event.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/smart_door_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/smart_door/door_status_bar.dart';
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
@ -12,17 +17,20 @@ class DoorLockButton extends StatefulWidget {
|
||||
const DoorLockButton({
|
||||
super.key,
|
||||
required this.doorLock,
|
||||
required this.smartDoorModel,
|
||||
});
|
||||
|
||||
final DeviceModel doorLock;
|
||||
final SmartDoorModel smartDoorModel;
|
||||
@override
|
||||
State<DoorLockButton> createState() => _DoorLockButtonState();
|
||||
State<DoorLockButton> createState() => _DoorLockButtonState(smartDoorModel: smartDoorModel);
|
||||
}
|
||||
|
||||
class _DoorLockButtonState extends State<DoorLockButton>
|
||||
with SingleTickerProviderStateMixin {
|
||||
class _DoorLockButtonState extends State<DoorLockButton> with SingleTickerProviderStateMixin {
|
||||
late AnimationController _animationController;
|
||||
late Animation<double> _animation;
|
||||
SmartDoorModel smartDoorModel;
|
||||
_DoorLockButtonState({required this.smartDoorModel});
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -34,29 +42,27 @@ class _DoorLockButtonState extends State<DoorLockButton>
|
||||
_animation = Tween<double>(begin: 0, end: 1.0).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 ?? "");
|
||||
}
|
||||
// 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<SmartDoorBloc>(context)
|
||||
.add(UpdateLockEvent(value: smartDoorModel.normalOpenSwitch));
|
||||
} 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 ?? "");
|
||||
}
|
||||
// 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 ?? "");
|
||||
// }
|
||||
}
|
||||
setState(() {});
|
||||
});
|
||||
@ -70,119 +76,102 @@ class _DoorLockButtonState extends State<DoorLockButton>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocConsumer<DevicesCubit, DevicesState>(
|
||||
listener: (context, state) {
|
||||
if (state is GetDeviceStatusError) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.errorMsg),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(
|
||||
right: context.width * 0.25 / 2,
|
||||
left: context.width * 0.25 / 2,
|
||||
bottom: context.width * 0.2 / 2,
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(
|
||||
right: context.width * 0.25 / 2,
|
||||
left: context.width * 0.25 / 2,
|
||||
bottom: context.width * 0.2 / 2,
|
||||
),
|
||||
child: InkWell(
|
||||
overlayColor:
|
||||
MaterialStateProperty.all(ColorsManager.primaryColorWithOpacity.withOpacity(0.1)),
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
onTapDown: (details) {
|
||||
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();
|
||||
}
|
||||
},
|
||||
onTapUp: (details) {
|
||||
if (_animationController.status == AnimationStatus.forward) {
|
||||
_animationController.reverse();
|
||||
} else if (_animationController.status == AnimationStatus.reverse) {
|
||||
_animationController.forward();
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
width: context.width * 06,
|
||||
height: context.width * 0.6,
|
||||
margin: const EdgeInsets.all(10),
|
||||
decoration: const BoxDecoration(
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey,
|
||||
blurRadius: 18,
|
||||
offset: Offset(6, 7),
|
||||
blurStyle: BlurStyle.outer,
|
||||
),
|
||||
],
|
||||
color: Color(0xFFEBECED),
|
||||
borderRadius: BorderRadius.all(Radius.circular(999)),
|
||||
),
|
||||
child: InkWell(
|
||||
overlayColor: MaterialStateProperty.all(
|
||||
ColorsManager.primaryColorWithOpacity.withOpacity(0.1)),
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
onTapDown: (details) {
|
||||
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();
|
||||
}
|
||||
},
|
||||
onTapUp: (details) {
|
||||
if (_animationController.status == AnimationStatus.forward) {
|
||||
_animationController.reverse();
|
||||
} else if (_animationController.status ==
|
||||
AnimationStatus.reverse) {
|
||||
_animationController.forward();
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
width: context.width * 06,
|
||||
height: context.width * 0.6,
|
||||
margin: const EdgeInsets.all(10),
|
||||
decoration: const BoxDecoration(
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey,
|
||||
blurRadius: 18,
|
||||
offset: Offset(6, 7),
|
||||
blurStyle: BlurStyle.outer,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(25),
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Container(
|
||||
margin: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
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,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
color: Color(0xFFEBECED),
|
||||
borderRadius: BorderRadius.all(Radius.circular(999)),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(25),
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Container(
|
||||
margin: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
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: SvgPicture.asset(
|
||||
Assets.assetsIconsDoorlockAssetsLockIcon,
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: SvgPicture.asset(
|
||||
smartDoorModel.normalOpenSwitch
|
||||
? Assets.doorUnlockIcon
|
||||
: Assets.assetsIconsDoorlockAssetsLockIcon,
|
||||
),
|
||||
SizedBox.expand(
|
||||
child: CircularProgressIndicator(
|
||||
value: _animation.value,
|
||||
strokeWidth: 15,
|
||||
backgroundColor: Colors.transparent,
|
||||
valueColor: const AlwaysStoppedAnimation<Color>(
|
||||
ColorsManager.primaryColor),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox.expand(
|
||||
child: CircularProgressIndicator(
|
||||
value: _animation.value,
|
||||
strokeWidth: 15,
|
||||
backgroundColor: Colors.transparent,
|
||||
valueColor: const AlwaysStoppedAnimation<Color>(ColorsManager.primaryColor),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/smart_door/members_management_view.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/smart_door/smart_linkage_view.dart';
|
||||
@ -32,8 +33,7 @@ class DoorLockGrid extends StatelessWidget {
|
||||
doorLockButtons[index]['page'] != null
|
||||
? Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
doorLockButtons[index]['page'] as Widget,
|
||||
builder: (context) => doorLockButtons[index]['page'] as Widget,
|
||||
),
|
||||
)
|
||||
: null;
|
||||
@ -51,11 +51,13 @@ class DoorLockGrid extends StatelessWidget {
|
||||
const SizedBox(
|
||||
height: 15,
|
||||
),
|
||||
FittedBox(
|
||||
child: BodySmall(
|
||||
text: doorLockButtons[index]['title'] as String,
|
||||
// doorLockButtons.keys.elementAt(index),
|
||||
textAlign: TextAlign.center,
|
||||
Flexible(
|
||||
child: FittedBox(
|
||||
child: BodySmall(
|
||||
text: doorLockButtons[index]['title'] as String,
|
||||
// doorLockButtons.keys.elementAt(index),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@ -73,7 +75,7 @@ List<Map<String, dynamic>> doorLockButtons = [
|
||||
'page': const UnlockingRecordsView(),
|
||||
},
|
||||
{
|
||||
'title': 'Memebers Managment',
|
||||
'title': 'Members Management',
|
||||
'image': Assets.assetsIconsDoorlockAssetsMembersManagement,
|
||||
'page': const MembersManagementView(),
|
||||
},
|
||||
|
||||
@ -1,9 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/smart_door_bloc/smart_door_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/smart_door_bloc/smart_door_event.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/smart_door_bloc/smart_door_state.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/smart_door_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/smart_door/door_button.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/smart_door/door_grid.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/smart_door/door_status_bar.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
@ -11,65 +17,114 @@ import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/font_manager.dart';
|
||||
|
||||
class DoorInterface extends StatelessWidget {
|
||||
const DoorInterface({super.key, required this.doorlock});
|
||||
const DoorInterface({super.key, required this.doorLock});
|
||||
|
||||
final DeviceModel doorlock;
|
||||
final DeviceModel doorLock;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnnotatedRegion(
|
||||
value: SystemUiOverlayStyle(
|
||||
statusBarColor: ColorsManager.primaryColor.withOpacity(0.5),
|
||||
statusBarIconBrightness: Brightness.light,
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Scaffold(
|
||||
backgroundColor: ColorsManager.backgroundColor,
|
||||
extendBodyBehindAppBar: true,
|
||||
extendBody: true,
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
centerTitle: true,
|
||||
title: BodyLarge(
|
||||
text: doorlock.name ?? "",
|
||||
fontColor: ColorsManager.primaryColor,
|
||||
fontWeight: FontsManager.bold,
|
||||
return BlocProvider(
|
||||
create: (context) => SmartDoorBloc(deviceId: doorLock.uuid ?? '')..add(InitialEvent()),
|
||||
child: BlocConsumer<SmartDoorBloc, SmartDoorState>(listener: (context, state) {
|
||||
if (state is FailedState) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.errorMessage),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
}, builder: (context, state) {
|
||||
SmartDoorModel smartDoorModel = SmartDoorModel(
|
||||
unlockFingerprint: 0,
|
||||
unlockPassword: 0,
|
||||
unlockTemporary: 0,
|
||||
unlockCard: 0,
|
||||
unlockAlarm: '',
|
||||
unlockRequest: 0,
|
||||
residualElectricity: 0,
|
||||
reverseLock: false,
|
||||
unlockApp: 0,
|
||||
hijack: false,
|
||||
doorbell: false,
|
||||
unlockOfflinePd: '',
|
||||
unlockOfflineClear: '',
|
||||
unlockDoubleKit: '',
|
||||
remoteNoPdSetkey: '',
|
||||
remoteNoDpKey: '',
|
||||
normalOpenSwitch: false);
|
||||
|
||||
if (state is UpdateState) {
|
||||
smartDoorModel = state.smartDoorModel;
|
||||
} else if (state is LoadingNewSate) {
|
||||
smartDoorModel = state.smartDoorModel;
|
||||
}
|
||||
|
||||
return AnnotatedRegion(
|
||||
value: SystemUiOverlayStyle(
|
||||
statusBarColor: ColorsManager.primaryColor.withOpacity(0.5),
|
||||
statusBarIconBrightness: Brightness.light,
|
||||
),
|
||||
body: Container(
|
||||
width: MediaQuery.sizeOf(context).width,
|
||||
height: MediaQuery.sizeOf(context).height,
|
||||
decoration: const BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage(
|
||||
Assets.assetsImagesBackground,
|
||||
child: SafeArea(
|
||||
child: Scaffold(
|
||||
backgroundColor: ColorsManager.backgroundColor,
|
||||
extendBodyBehindAppBar: true,
|
||||
extendBody: true,
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
centerTitle: true,
|
||||
title: BodyLarge(
|
||||
text: doorLock.name ?? "",
|
||||
fontColor: ColorsManager.primaryColor,
|
||||
fontWeight: FontsManager.bold,
|
||||
),
|
||||
fit: BoxFit.cover,
|
||||
opacity: 0.4,
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
top: Constants.appBarHeight,
|
||||
left: Constants.defaultPadding,
|
||||
right: Constants.defaultPadding,
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
const DoorLockStatusBar(),
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
DoorLockButton(doorLock: doorlock),
|
||||
const DoorLockGrid(),
|
||||
],
|
||||
body: state is LoadingInitialState
|
||||
? const Center(
|
||||
child: DefaultContainer(
|
||||
width: 50, height: 50, child: CircularProgressIndicator()),
|
||||
)
|
||||
],
|
||||
)),
|
||||
: Container(
|
||||
width: MediaQuery.sizeOf(context).width,
|
||||
height: MediaQuery.sizeOf(context).height,
|
||||
decoration: const BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage(
|
||||
Assets.assetsImagesBackground,
|
||||
),
|
||||
fit: BoxFit.cover,
|
||||
opacity: 0.4,
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
top: Constants.appBarHeight,
|
||||
left: Constants.defaultPadding,
|
||||
right: Constants.defaultPadding,
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
DoorLockStatusBar(
|
||||
smartDoorModel: smartDoorModel,
|
||||
),
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
DoorLockButton(
|
||||
doorLock: doorLock,
|
||||
smartDoorModel: smartDoorModel,
|
||||
),
|
||||
const DoorLockGrid(),
|
||||
],
|
||||
)
|
||||
],
|
||||
)),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,20 +1,29 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:syncrow_app/features/devices/model/smart_door_model.dart';
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
|
||||
class DoorLockStatusBar extends StatelessWidget {
|
||||
const DoorLockStatusBar({
|
||||
required this.smartDoorModel,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final SmartDoorModel smartDoorModel;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String batteryIc = Assets.assetsIconsBatteryDmOnPerOnchargOfflowOffpmOffstChargeddmOn;
|
||||
if (smartDoorModel.residualElectricity < 90) {
|
||||
batteryIc = Assets.assetsIconsBatteryDmOnPerOnchargOfflowOffpmOffstChargeddmOn;
|
||||
} else if (smartDoorModel.residualElectricity < 10) {
|
||||
batteryIc = Assets.assetsIconsBatteryDmOnPerOnchargOnlowOnpmOffstlowBatterydmOn;
|
||||
}
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
SvgPicture.asset(Assets.assetsIconsWifi),
|
||||
SvgPicture.asset(Assets
|
||||
.assetsIconsBatteryDmOffPerOnchargOfflowOffpmOffstDefaultdmOff),
|
||||
SvgPicture.asset(batteryIc),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user