From 0eea5242e1ae3cd4d0d9206c7f362c02fcfa1f9c Mon Sep 17 00:00:00 2001 From: Abdullah Alassaf Date: Thu, 23 May 2024 02:45:31 +0300 Subject: [PATCH] Added smart door bloc --- .../icons/doorlock-assets/door_un_look_ic.svg | 17 ++ .../bloc/smart_door_bloc/smart_door_bloc.dart | 105 ++------ .../smart_door_bloc/smart_door_state.dart | 9 +- ...{smart_door.dart => smart_door_model.dart} | 6 +- .../widgets/ACs/category_view_app_bar.dart | 1 - .../view/widgets/room_page_switch.dart | 6 +- .../view/widgets/smart_door/door_button.dart | 253 +++++++++--------- .../view/widgets/smart_door/door_grid.dart | 18 +- .../widgets/smart_door/door_interface.dart | 153 +++++++---- .../widgets/smart_door/door_status_bar.dart | 13 +- lib/generated/assets.dart | 1 + 11 files changed, 291 insertions(+), 291 deletions(-) create mode 100644 assets/icons/doorlock-assets/door_un_look_ic.svg rename lib/features/devices/model/{smart_door.dart => smart_door_model.dart} (97%) diff --git a/assets/icons/doorlock-assets/door_un_look_ic.svg b/assets/icons/doorlock-assets/door_un_look_ic.svg new file mode 100644 index 0000000..b647ec8 --- /dev/null +++ b/assets/icons/doorlock-assets/door_un_look_ic.svg @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + 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 0bc672b..de0b4c7 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 @@ -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 { +class SmartDoorBloc extends Bloc { final String deviceId; late SmartDoorModel deviceStatus; SmartDoorBloc({required this.deviceId}) : super(InitialState()) { - on(_fetchThreeGangStatus); - on(_changeFirstSwitch); - on(_changeSecondSwitch); - on(_changeThirdSwitch); - on(_allOff); - on(_allOn); + on(_fetchSmartDoorStatus); + on(_updateLock); } - void _fetchThreeGangStatus(InitialEvent event, Emitter emit) async { + void _fetchSmartDoorStatus(InitialEvent event, Emitter emit) async { emit(LoadingInitialState()); try { var response = await DevicesAPI.getDeviceStatus(deviceId); @@ -29,94 +24,24 @@ class SmartDoorBloc extends Bloc { 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 emit) async { - emit(LoadingNewSate(threeGangModel: deviceStatus)); + void _updateLock(UpdateLockEvent event, Emitter 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 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 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 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 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)); } } diff --git a/lib/features/devices/bloc/smart_door_bloc/smart_door_state.dart b/lib/features/devices/bloc/smart_door_bloc/smart_door_state.dart index 5f4b1c0..12cab76 100644 --- a/lib/features/devices/bloc/smart_door_bloc/smart_door_state.dart +++ b/lib/features/devices/bloc/smart_door_bloc/smart_door_state.dart @@ -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 get props => [error]; + List get props => [errorMessage]; } diff --git a/lib/features/devices/model/smart_door.dart b/lib/features/devices/model/smart_door_model.dart similarity index 97% rename from lib/features/devices/model/smart_door.dart rename to lib/features/devices/model/smart_door_model.dart index eac9468..2403941 100644 --- a/lib/features/devices/model/smart_door.dart +++ b/lib/features/devices/model/smart_door_model.dart @@ -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 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') { diff --git a/lib/features/devices/view/widgets/ACs/category_view_app_bar.dart b/lib/features/devices/view/widgets/ACs/category_view_app_bar.dart index 4d952b0..4a4e01f 100644 --- a/lib/features/devices/view/widgets/ACs/category_view_app_bar.dart +++ b/lib/features/devices/view/widgets/ACs/category_view_app_bar.dart @@ -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'; diff --git a/lib/features/devices/view/widgets/room_page_switch.dart b/lib/features/devices/view/widgets/room_page_switch.dart index 453e270..13e5b24 100644 --- a/lib/features/devices/view/widgets/room_page_switch.dart +++ b/lib/features/devices/view/widgets/room_page_switch.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; 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 171f5ab..08339ed 100644 --- a/lib/features/devices/view/widgets/smart_door/door_button.dart +++ b/lib/features/devices/view/widgets/smart_door/door_button.dart @@ -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 createState() => _DoorLockButtonState(); + State createState() => _DoorLockButtonState(smartDoorModel: smartDoorModel); } -class _DoorLockButtonState extends State - with SingleTickerProviderStateMixin { +class _DoorLockButtonState extends State with SingleTickerProviderStateMixin { late AnimationController _animationController; late Animation _animation; + SmartDoorModel smartDoorModel; + _DoorLockButtonState({required this.smartDoorModel}); @override void initState() { @@ -34,29 +42,27 @@ class _DoorLockButtonState extends State _animation = Tween(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(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 @override Widget build(BuildContext context) { - return BlocConsumer( - 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( - ColorsManager.primaryColor), - ), - ) - ], + ), ), - ), + SizedBox.expand( + child: CircularProgressIndicator( + value: _animation.value, + strokeWidth: 15, + backgroundColor: Colors.transparent, + valueColor: const AlwaysStoppedAnimation(ColorsManager.primaryColor), + ), + ) + ], ), ), - ); - }, + ), + ), ); } } diff --git a/lib/features/devices/view/widgets/smart_door/door_grid.dart b/lib/features/devices/view/widgets/smart_door/door_grid.dart index 920d5c0..311b25f 100644 --- a/lib/features/devices/view/widgets/smart_door/door_grid.dart +++ b/lib/features/devices/view/widgets/smart_door/door_grid.dart @@ -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> doorLockButtons = [ 'page': const UnlockingRecordsView(), }, { - 'title': 'Memebers Managment', + 'title': 'Members Management', 'image': Assets.assetsIconsDoorlockAssetsMembersManagement, 'page': const MembersManagementView(), }, diff --git a/lib/features/devices/view/widgets/smart_door/door_interface.dart b/lib/features/devices/view/widgets/smart_door/door_interface.dart index bf5945f..d9585f3 100644 --- a/lib/features/devices/view/widgets/smart_door/door_interface.dart +++ b/lib/features/devices/view/widgets/smart_door/door_interface.dart @@ -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(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(), + ], + ) + ], + )), + ), + ), ), - ), - ), + ); + }), ); } } diff --git a/lib/features/devices/view/widgets/smart_door/door_status_bar.dart b/lib/features/devices/view/widgets/smart_door/door_status_bar.dart index 2b2b761..ea7daac 100644 --- a/lib/features/devices/view/widgets/smart_door/door_status_bar.dart +++ b/lib/features/devices/view/widgets/smart_door/door_status_bar.dart @@ -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), ], ); } diff --git a/lib/generated/assets.dart b/lib/generated/assets.dart index 2c23ef1..a749611 100644 --- a/lib/generated/assets.dart +++ b/lib/generated/assets.dart @@ -276,6 +276,7 @@ class Assets { /// assets/icons/doorlock-assets/lockIcon.svg static const String assetsIconsDoorlockAssetsLockIcon = "assets/icons/doorlock-assets/lockIcon.svg"; + static const String doorUnlockIcon = "assets/icons/doorlock-assets/door_un_look_ic.svg"; /// Assets for assetsIconsDoorlockAssetsMembersManagement /// assets/icons/doorlock-assets/members-management.svg