mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
space type connection
This commit is contained in:
@ -158,6 +158,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
|||||||
user = UserModel.fromToken(token);
|
user = UserModel.fromToken(token);
|
||||||
loginEmailController.clear();
|
loginEmailController.clear();
|
||||||
loginPasswordController.clear();
|
loginPasswordController.clear();
|
||||||
|
debugPrint("token " + token.accessToken);
|
||||||
emit(LoginSuccess());
|
emit(LoginSuccess());
|
||||||
} else {
|
} else {
|
||||||
emit(const LoginFailure(error: 'Something went wrong'));
|
emit(const LoginFailure(error: 'Something went wrong'));
|
||||||
|
@ -62,16 +62,19 @@ class CeilingSensorBloc extends Bloc<CeilingSensorEvent, CeilingSensorState> {
|
|||||||
deviceStatus.noBodyTime = event.value;
|
deviceStatus.noBodyTime = event.value;
|
||||||
} else if (event.code == 'moving_max_dis') {
|
} else if (event.code == 'moving_max_dis') {
|
||||||
deviceStatus.maxDistance = event.value;
|
deviceStatus.maxDistance = event.value;
|
||||||
|
} else if (event.code == 'scene') {
|
||||||
|
deviceStatus.spaceType = getSpaceType(event.value);
|
||||||
}
|
}
|
||||||
emit(CeilingUpdateState(ceilingSensorModel: deviceStatus));
|
emit(CeilingUpdateState(ceilingSensorModel: deviceStatus));
|
||||||
await _runDeBouncer(
|
await _runDeBouncer(
|
||||||
deviceId: deviceId, code: event.code, value: event.value);
|
deviceId: deviceId, code: event.code, value: event.value, emit: emit);
|
||||||
}
|
}
|
||||||
|
|
||||||
_runDeBouncer({
|
_runDeBouncer({
|
||||||
required String deviceId,
|
required String deviceId,
|
||||||
required String code,
|
required String code,
|
||||||
required dynamic value,
|
required dynamic value,
|
||||||
|
required Emitter<CeilingSensorState> emit,
|
||||||
}) {
|
}) {
|
||||||
if (_timer != null) {
|
if (_timer != null) {
|
||||||
_timer!.cancel();
|
_timer!.cancel();
|
||||||
@ -84,6 +87,11 @@ class CeilingSensorBloc extends Bloc<CeilingSensorEvent, CeilingSensorState> {
|
|||||||
if (!response) {
|
if (!response) {
|
||||||
add(CeilingInitialEvent());
|
add(CeilingInitialEvent());
|
||||||
}
|
}
|
||||||
|
if (response == true && code == 'scene') {
|
||||||
|
emit(CeilingLoadingInitialState());
|
||||||
|
await Future.delayed(const Duration(seconds: 1));
|
||||||
|
add(CeilingInitialEvent());
|
||||||
|
}
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
await Future.delayed(const Duration(milliseconds: 500));
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
add(CeilingInitialEvent());
|
add(CeilingInitialEvent());
|
||||||
|
@ -10,7 +10,7 @@ class CeilingSensorModel {
|
|||||||
String bodyMovement;
|
String bodyMovement;
|
||||||
String noBodyTime;
|
String noBodyTime;
|
||||||
int maxDistance;
|
int maxDistance;
|
||||||
String spaceType;
|
SpaceTypes spaceType;
|
||||||
|
|
||||||
CeilingSensorModel({
|
CeilingSensorModel({
|
||||||
required this.presenceState,
|
required this.presenceState,
|
||||||
@ -33,7 +33,7 @@ class CeilingSensorModel {
|
|||||||
String _bodyMovement = 'none';
|
String _bodyMovement = 'none';
|
||||||
String _noBodyTime = 'none';
|
String _noBodyTime = 'none';
|
||||||
int _maxDis = 0;
|
int _maxDis = 0;
|
||||||
String _spaceType = 'none';
|
SpaceTypes _spaceType = SpaceTypes.none;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (var status in jsonList) {
|
for (var status in jsonList) {
|
||||||
@ -42,7 +42,7 @@ class CeilingSensorModel {
|
|||||||
_presenceState = status.value ?? 'none';
|
_presenceState = status.value ?? 'none';
|
||||||
break;
|
break;
|
||||||
case 'scene':
|
case 'scene':
|
||||||
_spaceType = status.value ?? 'none';
|
_spaceType = getSpaceType(status.value ?? 'none');
|
||||||
break;
|
break;
|
||||||
case 'sensitivity':
|
case 'sensitivity':
|
||||||
_sensitivity = status.value is int
|
_sensitivity = status.value is int
|
||||||
@ -92,3 +92,27 @@ class CeilingSensorModel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum SpaceTypes {
|
||||||
|
none,
|
||||||
|
parlour,
|
||||||
|
area,
|
||||||
|
toilet,
|
||||||
|
bedroom,
|
||||||
|
}
|
||||||
|
|
||||||
|
SpaceTypes getSpaceType(String value) {
|
||||||
|
switch (value) {
|
||||||
|
case 'parlour':
|
||||||
|
return SpaceTypes.parlour;
|
||||||
|
case 'area':
|
||||||
|
return SpaceTypes.area;
|
||||||
|
case 'toilet':
|
||||||
|
return SpaceTypes.toilet;
|
||||||
|
case 'bedroom':
|
||||||
|
return SpaceTypes.bedroom;
|
||||||
|
case 'none':
|
||||||
|
default:
|
||||||
|
return SpaceTypes.none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -99,15 +99,14 @@ class CeilingSensorControls extends StatelessWidget
|
|||||||
description: 'Detection Range',
|
description: 'Detection Range',
|
||||||
),
|
),
|
||||||
PresenceSpaceType(
|
PresenceSpaceType(
|
||||||
listOfIcons: const [
|
|
||||||
Assets.office,
|
|
||||||
Assets.parlour,
|
|
||||||
Assets.dyi,
|
|
||||||
Assets.bathroom,
|
|
||||||
Assets.bedroom,
|
|
||||||
],
|
|
||||||
description: 'Space Type',
|
description: 'Space Type',
|
||||||
value: model.spaceType,
|
value: model.spaceType,
|
||||||
|
action: (String value) => context.read<CeilingSensorBloc>().add(
|
||||||
|
CeilingChangeValueEvent(
|
||||||
|
code: 'scene',
|
||||||
|
value: value,
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
PresenceUpdateData(
|
PresenceUpdateData(
|
||||||
value: model.sensitivity.toDouble(),
|
value: model.sensitivity.toDouble(),
|
||||||
|
@ -1,24 +1,33 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/shared/device_controls_container.dart';
|
import 'package:syncrow_web/pages/device_managment/shared/device_controls_container.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/model/ceiling_sensor_model.dart';
|
||||||
|
|
||||||
class PresenceSpaceType extends StatelessWidget {
|
class PresenceSpaceType extends StatelessWidget {
|
||||||
const PresenceSpaceType({
|
const PresenceSpaceType({
|
||||||
super.key,
|
super.key,
|
||||||
required this.listOfIcons,
|
|
||||||
required this.description,
|
required this.description,
|
||||||
required this.value,
|
required this.value,
|
||||||
|
required this.action,
|
||||||
});
|
});
|
||||||
|
|
||||||
final List<String> listOfIcons;
|
|
||||||
final String description;
|
final String description;
|
||||||
final String value;
|
final SpaceTypes value;
|
||||||
|
final void Function(String value) action;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final Map<SpaceTypes, String> spaceTypeIcons = {
|
||||||
|
SpaceTypes.none: Assets.office,
|
||||||
|
SpaceTypes.parlour: Assets.parlour,
|
||||||
|
SpaceTypes.area: Assets.dyi,
|
||||||
|
SpaceTypes.toilet: Assets.bathroom,
|
||||||
|
SpaceTypes.bedroom: Assets.bedroom,
|
||||||
|
};
|
||||||
|
|
||||||
return DeviceControlsContainer(
|
return DeviceControlsContainer(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
@ -38,23 +47,28 @@ class PresenceSpaceType extends StatelessWidget {
|
|||||||
Wrap(
|
Wrap(
|
||||||
runSpacing: 8,
|
runSpacing: 8,
|
||||||
spacing: 16,
|
spacing: 16,
|
||||||
children: [
|
children: spaceTypeIcons.entries.map((entry) {
|
||||||
...listOfIcons.map((icon) => Container(
|
final icon = entry.value;
|
||||||
decoration: BoxDecoration(
|
final spaceType = entry.key;
|
||||||
borderRadius: BorderRadius.circular(100),
|
return GestureDetector(
|
||||||
border: Border.all(
|
onTap: () => action(spaceType.name),
|
||||||
color: icon.contains(value)
|
child: Container(
|
||||||
? ColorsManager.blueColor
|
decoration: BoxDecoration(
|
||||||
: Colors.transparent,
|
borderRadius: BorderRadius.circular(100),
|
||||||
),
|
border: Border.all(
|
||||||
|
color: value == spaceType
|
||||||
|
? ColorsManager.blueColor
|
||||||
|
: Colors.transparent,
|
||||||
),
|
),
|
||||||
child: SvgPicture.asset(
|
),
|
||||||
icon,
|
child: SvgPicture.asset(
|
||||||
width: 40,
|
icon,
|
||||||
height: 40,
|
width: 40,
|
||||||
),
|
height: 40,
|
||||||
)),
|
),
|
||||||
],
|
),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
Reference in New Issue
Block a user