Added Control functoinalty on the DoorLock

This commit is contained in:
Mohammad Salameh
2024-04-29 11:38:11 +03:00
parent 6d720546f8
commit a12f006d63
4 changed files with 149 additions and 112 deletions

View File

@ -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(),
),
),
);
},

View File

@ -140,7 +140,7 @@ class AuthCubit extends Cubit<AuthState> {
final value =
await const FlutterSecureStorage().read(key: Token.loginAccessTokenKey);
if (value == null) {
if (value == null || value.isEmpty) {
emit(AuthTokenError(message: "Token not found"));
return;
}

View File

@ -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<DoorLockButton> createState() => _DoorLockButtonState();
}
@ -28,9 +34,29 @@ class _DoorLockButtonState extends State<DoorLockButton>
_animation = Tween<double>(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<DoorLockButton>
@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<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,
),
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<Color>(
ColorsManager.primaryColor),
),
)
],
),
SizedBox.expand(
child: CircularProgressIndicator(
value: _animation.value,
strokeWidth: 15,
backgroundColor: Colors.transparent,
valueColor: const AlwaysStoppedAnimation<Color>(
ColorsManager.primaryColor),
),
)
],
),
),
),
),
),
);
},
);
}
}

View File

@ -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(),
],
)
],