diff --git a/lib/features/app_layout/view/app_layout.dart b/lib/features/app_layout/view/app_layout.dart index 35602e1..5e6458e 100644 --- a/lib/features/app_layout/view/app_layout.dart +++ b/lib/features/app_layout/view/app_layout.dart @@ -26,22 +26,15 @@ class AppLayout extends StatelessWidget { ), child: SafeArea( child: Scaffold( - backgroundColor: ColorsManager.backgroundColor, - extendBodyBehindAppBar: true, - extendBody: true, - appBar: HomeCubit.getInstance().spaces != null - ? const DefaultAppBar() - : null, - body: const AppBody(), - bottomNavigationBar: const DefaultNavBar(), - floatingActionButton: FloatingActionButton( - onPressed: () { - Navigator.of(context).push(CustomPageRoute( - builder: (context) => const SmartLinkgeView())); - }, - backgroundColor: ColorsManager.primaryColor, - child: const Icon(Icons.refresh), - )), + backgroundColor: ColorsManager.backgroundColor, + extendBodyBehindAppBar: true, + extendBody: true, + appBar: HomeCubit.getInstance().spaces != null + ? const DefaultAppBar() + : null, + body: const AppBody(), + bottomNavigationBar: const DefaultNavBar(), + ), ), ); }, diff --git a/lib/features/auth/bloc/auth_cubit.dart b/lib/features/auth/bloc/auth_cubit.dart index 4e10a42..daa909a 100644 --- a/lib/features/auth/bloc/auth_cubit.dart +++ b/lib/features/auth/bloc/auth_cubit.dart @@ -140,7 +140,7 @@ class AuthCubit extends Cubit { final value = await const FlutterSecureStorage().read(key: Token.loginAccessTokenKey); - if (value == null) { + if (value == null || value.isEmpty) { emit(AuthTokenError(message: "Token not found")); return; } 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 610ffad..cfc91c1 100644 --- a/lib/features/devices/view/widgets/smart_door/door_button.dart +++ b/lib/features/devices/view/widgets/smart_door/door_button.dart @@ -1,5 +1,9 @@ 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/devices_cubit.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/generated/assets.dart'; import 'package:syncrow_app/utils/context_extension.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; @@ -7,8 +11,10 @@ import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; class DoorLockButton extends StatefulWidget { const DoorLockButton({ super.key, + required this.doorLock, }); + final DeviceModel doorLock; @override State createState() => _DoorLockButtonState(); } @@ -28,9 +34,29 @@ class _DoorLockButtonState extends State _animation = Tween(begin: 0, end: 1.0).animate(_animationController) ..addListener(() { if (_animation.status == AnimationStatus.completed) { - //TODO send a request to lock the door but check if the door is already locked + 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 ?? ""); + } } else if (_animation.status == AnimationStatus.dismissed) { - //TODO send a request to unlock the door but check if the door is already unlocked + 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(() {}); }); @@ -44,101 +70,119 @@ class _DoorLockButtonState extends State @override Widget build(BuildContext context) { - 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)), + 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, ), - 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: 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: Center( - child: SvgPicture.asset( - Assets.doorlockAssetsLockIcon, + ], + 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.doorlockAssetsLockIcon, + ), + ), ), - ), + 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_interface.dart b/lib/features/devices/view/widgets/smart_door/door_interface.dart index cc5bcb2..905d45d 100644 --- a/lib/features/devices/view/widgets/smart_door/door_interface.dart +++ b/lib/features/devices/view/widgets/smart_door/door_interface.dart @@ -54,15 +54,15 @@ class DoorInterface extends StatelessWidget { left: Constants.defaultPadding, right: Constants.defaultPadding, ), - child: const Column( + child: Column( children: [ - DoorLockStatusBar(), + const DoorLockStatusBar(), Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - DoorLockButton(), - DoorLockGrid(), + DoorLockButton(doorLock: doorlock), + const DoorLockGrid(), ], ) ],