mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 10:06:16 +00:00
Added Control functoinalty on the DoorLock
This commit is contained in:
@ -26,22 +26,15 @@ class AppLayout extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
child: SafeArea(
|
child: SafeArea(
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
backgroundColor: ColorsManager.backgroundColor,
|
backgroundColor: ColorsManager.backgroundColor,
|
||||||
extendBodyBehindAppBar: true,
|
extendBodyBehindAppBar: true,
|
||||||
extendBody: true,
|
extendBody: true,
|
||||||
appBar: HomeCubit.getInstance().spaces != null
|
appBar: HomeCubit.getInstance().spaces != null
|
||||||
? const DefaultAppBar()
|
? const DefaultAppBar()
|
||||||
: null,
|
: null,
|
||||||
body: const AppBody(),
|
body: const AppBody(),
|
||||||
bottomNavigationBar: const DefaultNavBar(),
|
bottomNavigationBar: const DefaultNavBar(),
|
||||||
floatingActionButton: FloatingActionButton(
|
),
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context).push(CustomPageRoute(
|
|
||||||
builder: (context) => const SmartLinkgeView()));
|
|
||||||
},
|
|
||||||
backgroundColor: ColorsManager.primaryColor,
|
|
||||||
child: const Icon(Icons.refresh),
|
|
||||||
)),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -140,7 +140,7 @@ class AuthCubit extends Cubit<AuthState> {
|
|||||||
final value =
|
final value =
|
||||||
await const FlutterSecureStorage().read(key: Token.loginAccessTokenKey);
|
await const FlutterSecureStorage().read(key: Token.loginAccessTokenKey);
|
||||||
|
|
||||||
if (value == null) {
|
if (value == null || value.isEmpty) {
|
||||||
emit(AuthTokenError(message: "Token not found"));
|
emit(AuthTokenError(message: "Token not found"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.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/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';
|
||||||
@ -7,8 +11,10 @@ import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
|||||||
class DoorLockButton extends StatefulWidget {
|
class DoorLockButton extends StatefulWidget {
|
||||||
const DoorLockButton({
|
const DoorLockButton({
|
||||||
super.key,
|
super.key,
|
||||||
|
required this.doorLock,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
final DeviceModel doorLock;
|
||||||
@override
|
@override
|
||||||
State<DoorLockButton> createState() => _DoorLockButtonState();
|
State<DoorLockButton> createState() => _DoorLockButtonState();
|
||||||
}
|
}
|
||||||
@ -28,9 +34,29 @@ class _DoorLockButtonState extends State<DoorLockButton>
|
|||||||
_animation = Tween<double>(begin: 0, end: 1.0).animate(_animationController)
|
_animation = Tween<double>(begin: 0, end: 1.0).animate(_animationController)
|
||||||
..addListener(() {
|
..addListener(() {
|
||||||
if (_animation.status == AnimationStatus.completed) {
|
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) {
|
} 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(() {});
|
setState(() {});
|
||||||
});
|
});
|
||||||
@ -44,101 +70,119 @@ class _DoorLockButtonState extends State<DoorLockButton>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Padding(
|
return BlocConsumer<DevicesCubit, DevicesState>(
|
||||||
padding: EdgeInsets.only(
|
listener: (context, state) {
|
||||||
right: context.width * 0.25 / 2,
|
if (state is GetDeviceStatusError) {
|
||||||
left: context.width * 0.25 / 2,
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
bottom: context.width * 0.2 / 2,
|
SnackBar(
|
||||||
),
|
content: Text(state.errorMsg),
|
||||||
child: InkWell(
|
backgroundColor: Colors.red,
|
||||||
overlayColor: MaterialStateProperty.all(
|
),
|
||||||
ColorsManager.primaryColorWithOpacity.withOpacity(0.1)),
|
);
|
||||||
borderRadius: BorderRadius.circular(999),
|
}
|
||||||
onTapDown: (details) {
|
},
|
||||||
if (_animationController.status == AnimationStatus.dismissed) {
|
builder: (context, state) {
|
||||||
_animationController.forward();
|
return Padding(
|
||||||
} else if (_animationController.status == AnimationStatus.completed) {
|
padding: EdgeInsets.only(
|
||||||
_animationController.reverse();
|
right: context.width * 0.25 / 2,
|
||||||
} else if (_animationController.status == AnimationStatus.forward) {
|
left: context.width * 0.25 / 2,
|
||||||
_animationController.reverse();
|
bottom: context.width * 0.2 / 2,
|
||||||
} 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: Padding(
|
child: InkWell(
|
||||||
padding: const EdgeInsets.all(25),
|
overlayColor: MaterialStateProperty.all(
|
||||||
child: Stack(
|
ColorsManager.primaryColorWithOpacity.withOpacity(0.1)),
|
||||||
alignment: Alignment.center,
|
borderRadius: BorderRadius.circular(999),
|
||||||
children: [
|
onTapDown: (details) {
|
||||||
Container(
|
if (_animationController.status == AnimationStatus.dismissed) {
|
||||||
margin: const EdgeInsets.all(8),
|
_animationController.forward();
|
||||||
decoration: BoxDecoration(
|
} else if (_animationController.status ==
|
||||||
color: Colors.white,
|
AnimationStatus.completed) {
|
||||||
borderRadius: BorderRadius.circular(999),
|
_animationController.reverse();
|
||||||
boxShadow: [
|
} else if (_animationController.status ==
|
||||||
BoxShadow(
|
AnimationStatus.forward) {
|
||||||
color: Colors.white.withOpacity(0.5),
|
_animationController.reverse();
|
||||||
blurRadius: 30,
|
} else if (_animationController.status ==
|
||||||
offset: const Offset(-5, -5),
|
AnimationStatus.reverse) {
|
||||||
blurStyle: BlurStyle.outer,
|
_animationController.forward();
|
||||||
),
|
}
|
||||||
BoxShadow(
|
},
|
||||||
color: Colors.black.withOpacity(0.14),
|
onTapUp: (details) {
|
||||||
blurRadius: 25,
|
if (_animationController.status == AnimationStatus.forward) {
|
||||||
offset: const Offset(5, 5),
|
_animationController.reverse();
|
||||||
blurStyle: BlurStyle.outer,
|
} else if (_animationController.status ==
|
||||||
),
|
AnimationStatus.reverse) {
|
||||||
BoxShadow(
|
_animationController.forward();
|
||||||
color: Colors.black.withOpacity(0.14),
|
}
|
||||||
blurRadius: 30,
|
},
|
||||||
offset: const Offset(5, 5),
|
child: Container(
|
||||||
blurStyle: BlurStyle.inner,
|
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(
|
color: Color(0xFFEBECED),
|
||||||
Assets.doorlockAssetsLockIcon,
|
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),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
),
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,15 +54,15 @@ class DoorInterface extends StatelessWidget {
|
|||||||
left: Constants.defaultPadding,
|
left: Constants.defaultPadding,
|
||||||
right: Constants.defaultPadding,
|
right: Constants.defaultPadding,
|
||||||
),
|
),
|
||||||
child: const Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
DoorLockStatusBar(),
|
const DoorLockStatusBar(),
|
||||||
Column(
|
Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
DoorLockButton(),
|
DoorLockButton(doorLock: doorlock),
|
||||||
DoorLockGrid(),
|
const DoorLockGrid(),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
Reference in New Issue
Block a user