mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 18:16:21 +00:00
Added Control functoinalty on the DoorLock
This commit is contained in:
@ -34,14 +34,7 @@ class AppLayout extends StatelessWidget {
|
||||
: 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),
|
||||
)),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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,6 +70,18 @@ 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,
|
||||
@ -57,18 +95,22 @@ class _DoorLockButtonState extends State<DoorLockButton>
|
||||
onTapDown: (details) {
|
||||
if (_animationController.status == AnimationStatus.dismissed) {
|
||||
_animationController.forward();
|
||||
} else if (_animationController.status == AnimationStatus.completed) {
|
||||
} else if (_animationController.status ==
|
||||
AnimationStatus.completed) {
|
||||
_animationController.reverse();
|
||||
} else if (_animationController.status == AnimationStatus.forward) {
|
||||
} else if (_animationController.status ==
|
||||
AnimationStatus.forward) {
|
||||
_animationController.reverse();
|
||||
} else if (_animationController.status == AnimationStatus.reverse) {
|
||||
} else if (_animationController.status ==
|
||||
AnimationStatus.reverse) {
|
||||
_animationController.forward();
|
||||
}
|
||||
},
|
||||
onTapUp: (details) {
|
||||
if (_animationController.status == AnimationStatus.forward) {
|
||||
_animationController.reverse();
|
||||
} else if (_animationController.status == AnimationStatus.reverse) {
|
||||
} else if (_animationController.status ==
|
||||
AnimationStatus.reverse) {
|
||||
_animationController.forward();
|
||||
}
|
||||
},
|
||||
@ -140,5 +182,7 @@ class _DoorLockButtonState extends State<DoorLockButton>
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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(),
|
||||
],
|
||||
)
|
||||
],
|
||||
|
Reference in New Issue
Block a user