Compare commits

..
Author SHA1 Message Date
ashrafzarkanisala 308c8a44c5 pull changes 2024-10-09 13:29:12 +03:00
ashrafzarkanisala 7ca6e60d02 fix notification toggle 2024-10-09 13:28:19 +03:00
Abdullah Alassaf 03dfeabde4 Bug fixes 2024-10-08 23:14:41 +03:00
ashrafzarkanisala 79ec890244 fix oct/8 issues 2024-10-08 20:15:52 +03:00
ashrafzarkanisala 66f6b1cba9 fix bugs 2024-10-08 11:48:35 +03:00
Abdullah Alassaf c06f3d5a58 Changed the color of the device control container 2024-10-08 02:19:59 +03:00
Abdullah Alassaf 813f2f2693 Fixed design issues 2024-10-08 01:56:09 +03:00
Abdullah Alassaf d05328e998 Bug fixes 2024-10-07 22:53:18 +03:00
Abdullah ab22e15736 Merge pull request #33 from SyncrowIOT/garage_water_leack_devices
push water leak device
2024-10-07 11:58:25 +03:00
Abdullah 889d3dbd02 Merge pull request #32 from SyncrowIOT/garage_water_leack_devices
Garage water leack devices
2024-10-07 10:16:18 +03:00
60 changed files with 1064 additions and 1128 deletions
+5
View File
@@ -0,0 +1,5 @@
<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M38.0142 39.2553L35.3682 40H20.9308H19.9999H19.0691H1.24111C0.555643 40 0 39.4444 0 38.7589V1.24111C0 0.555643 0.555643 0 1.24111 0H19.0682H20.1226H20.9543H35.4255L38.2625 1.24111C38.9479 1.24111 39.5036 1.79675 39.5036 2.48221L39.2553 38.0142C39.2553 38.6997 38.6997 39.2553 38.0142 39.2553Z" fill="#E9E9E9"/>
<path d="M38.7589 0H35.0356C35.721 0 36.2767 0.555643 36.2767 1.24111V38.7589C36.2767 39.4444 35.721 40 35.0356 40H38.7589C39.4444 40 40 39.4444 40 38.7589V1.24111C40 0.555643 39.4444 0 38.7589 0Z" fill="#D1D1D1"/>
<path opacity="0.6" d="M21.375 31.8319V33.3213C21.375 34.0067 20.9553 34.5624 20.4375 34.5624H16.3125C15.7947 34.5624 15.375 34.0067 15.375 33.3213V31.8319C15.375 31.1465 15.7947 30.5908 16.3125 30.5908H20.4375C20.9553 30.5908 21.375 31.1465 21.375 31.8319Z" fill="#023DFE" fill-opacity="0.5"/>
</svg>

After

Width:  |  Height:  |  Size: 933 B

+7
View File
@@ -0,0 +1,7 @@
<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M38.0142 39.2553L35.3682 40H20.9308H19.9999H19.0691H1.24111C0.555643 40 0 39.4444 0 38.7589V1.24111C0 0.555643 0.555643 0 1.24111 0H19.0682H20.1226H20.9543H35.4255L38.2625 1.24111C38.9479 1.24111 39.5036 1.79675 39.5036 2.48221L39.2553 38.0142C39.2553 38.6997 38.6997 39.2553 38.0142 39.2553Z" fill="#E9E9E9"/>
<path d="M38.7589 0H35.0356C35.721 0 36.2767 0.555643 36.2767 1.24111V38.7589C36.2767 39.4444 35.721 40 35.0356 40H38.7589C39.4444 40 40 39.4444 40 38.7589V1.24111C40 0.555643 39.4444 0 38.7589 0Z" fill="#D1D1D1"/>
<path opacity="0.6" d="M12.0284 31.8319V33.3213C12.0284 34.0067 11.6087 34.5624 11.0909 34.5624H6.96594C6.44816 34.5624 6.02844 34.0067 6.02844 33.3213V31.8319C6.02844 31.1465 6.44816 30.5908 6.96594 30.5908H11.0909C11.6087 30.5908 12.0284 31.1465 12.0284 31.8319Z" fill="#023DFE" fill-opacity="0.5"/>
<path opacity="0.6" d="M26.0285 31.8319V33.3213C26.0285 34.0067 26.4482 34.5624 26.966 34.5624H31.091C31.6088 34.5624 32.0285 34.0067 32.0285 33.3213V31.8319C32.0285 31.1465 31.6088 30.5908 31.091 30.5908H26.966C26.4482 30.5908 26.0285 31.1465 26.0285 31.8319Z" fill="#023DFE" fill-opacity="0.5"/>
<path d="M19.0691 0H20.9308V40H19.0691V0Z" fill="#D1D1D1"/>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

@@ -64,13 +64,15 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
}
}
Future<void> selectTime(SelectTime event, Emitter<AccessState> emit,) async {
Future<void> selectTime(
SelectTime event,
Emitter<AccessState> emit,
) async {
emit(AccessLoaded());
final DateTime? picked = await showDatePicker(
context: event.context,
initialDate: DateTime.now(),
firstDate: DateTime.now().add(const Duration(days: -5095)),
firstDate: DateTime.now().add(const Duration(days: -5095)),
lastDate: DateTime.now().add(const Duration(days: 2095)),
);
if (picked != null) {
@@ -97,7 +99,8 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
}
} else {
if (effectiveTimeTimeStamp != null && selectedTimestamp < effectiveTimeTimeStamp!) {
CustomSnackBar.displaySnackBar('Expiration Time cannot be earlier than Effective Time.');
CustomSnackBar.displaySnackBar(
'Expiration Time cannot be earlier than Effective Time.');
} else {
endTime = selectedDateTime.toString().split('.').first;
expirationTimeTimeStamp = selectedTimestamp;
@@ -106,14 +109,11 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
}
}
emit(ChangeTimeState());
}
Future<void> _filterData(FilterDataEvent event, Emitter<AccessState> emit) async {
emit(AccessLoaded());
try {
print(event.emailAuthorizer?.toLowerCase());
// Convert search text to lower case for case-insensitive search
final searchText = event.passwordName?.toLowerCase() ?? '';
final searchEmailText = event.emailAuthorizer?.toLowerCase() ?? '';
@@ -121,15 +121,17 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
bool matchesCriteria = true;
// Convert timestamp to DateTime and extract date component
DateTime effectiveDate =
DateTime.fromMillisecondsSinceEpoch(int.parse(item.effectiveTime.toString()) * 1000)
.toUtc()
.toLocal();
DateTime.fromMillisecondsSinceEpoch(int.parse(item.effectiveTime.toString()) * 1000)
.toUtc()
.toLocal();
DateTime invalidDate =
DateTime.fromMillisecondsSinceEpoch(int.parse(item.invalidTime.toString()) * 1000)
.toUtc()
.toLocal();
DateTime effectiveDateAndTime = DateTime(effectiveDate.year, effectiveDate.month, effectiveDate.day,effectiveDate.hour,effectiveDate.minute);
DateTime invalidDateAndTime = DateTime(invalidDate.year, invalidDate.month, invalidDate.day,invalidDate.hour,invalidDate.minute);
DateTime.fromMillisecondsSinceEpoch(int.parse(item.invalidTime.toString()) * 1000)
.toUtc()
.toLocal();
DateTime effectiveDateAndTime = DateTime(effectiveDate.year, effectiveDate.month,
effectiveDate.day, effectiveDate.hour, effectiveDate.minute);
DateTime invalidDateAndTime = DateTime(invalidDate.year, invalidDate.month, invalidDate.day,
invalidDate.hour, invalidDate.minute);
// Filter by password name, making the search case-insensitive
if (searchText.isNotEmpty) {
@@ -139,7 +141,8 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
}
}
if (searchEmailText.isNotEmpty) {
final bool matchesName = item.authorizerEmail.toString().toLowerCase().contains(searchEmailText);
final bool matchesName =
item.authorizerEmail.toString().toLowerCase().contains(searchEmailText);
if (!matchesName) {
matchesCriteria = false;
}
@@ -147,13 +150,9 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
// Filter by start date only
if (event.startTime != null && event.endTime == null) {
DateTime startDateTime =
DateTime.fromMillisecondsSinceEpoch(event.startTime! * 1000).toUtc().toLocal();
startDateTime = DateTime(
startDateTime.year,
startDateTime.month,
startDateTime.day,
startDateTime.hour,
startDateTime.minute);
DateTime.fromMillisecondsSinceEpoch(event.startTime! * 1000).toUtc().toLocal();
startDateTime = DateTime(startDateTime.year, startDateTime.month, startDateTime.day,
startDateTime.hour, startDateTime.minute);
if (effectiveDateAndTime.isBefore(startDateTime)) {
matchesCriteria = false;
}
@@ -161,14 +160,9 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
// Filter by end date only
if (event.endTime != null && event.startTime == null) {
DateTime startDateTime =
DateTime.fromMillisecondsSinceEpoch(event.endTime! * 1000).toUtc().toLocal();
startDateTime = DateTime(
startDateTime.year,
startDateTime.month,
startDateTime.day,
startDateTime.hour,
startDateTime.minute
);
DateTime.fromMillisecondsSinceEpoch(event.endTime! * 1000).toUtc().toLocal();
startDateTime = DateTime(startDateTime.year, startDateTime.month, startDateTime.day,
startDateTime.hour, startDateTime.minute);
if (invalidDateAndTime.isAfter(startDateTime)) {
matchesCriteria = false;
}
@@ -177,12 +171,15 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
// Filter by both start date and end date
if (event.startTime != null && event.endTime != null) {
DateTime startDateTime =
DateTime.fromMillisecondsSinceEpoch(event.startTime! * 1000).toUtc().toLocal();
DateTime.fromMillisecondsSinceEpoch(event.startTime! * 1000).toUtc().toLocal();
DateTime endDateTime =
DateTime.fromMillisecondsSinceEpoch(event.endTime! * 1000).toUtc().toLocal();
startDateTime = DateTime(startDateTime.year, startDateTime.month, startDateTime.day,startDateTime.hour,startDateTime.minute);
endDateTime = DateTime(endDateTime.year, endDateTime.month, endDateTime.day,endDateTime.hour,endDateTime.minute);
if (effectiveDateAndTime.isBefore(startDateTime) || invalidDateAndTime.isAfter(endDateTime)) {
DateTime.fromMillisecondsSinceEpoch(event.endTime! * 1000).toUtc().toLocal();
startDateTime = DateTime(startDateTime.year, startDateTime.month, startDateTime.day,
startDateTime.hour, startDateTime.minute);
endDateTime = DateTime(endDateTime.year, endDateTime.month, endDateTime.day,
endDateTime.hour, endDateTime.minute);
if (effectiveDateAndTime.isBefore(startDateTime) ||
invalidDateAndTime.isAfter(endDateTime)) {
matchesCriteria = false;
}
}
@@ -205,7 +202,6 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
}
}
resetSearch(ResetSearch event, Emitter<AccessState> emit) async {
emit(AccessLoaded());
startTime = 'Start Time';
@@ -224,7 +220,6 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
" ${dateTime.hour.toString().padLeft(2, '0')}:${dateTime.minute.toString().padLeft(2, '0')}";
}
Future<void> onTabChanged(TabChangedEvent event, Emitter<AccessState> emit) async {
try {
emit(AccessLoaded());
@@ -257,6 +252,4 @@ class AccessBloc extends Bloc<AccessEvent, AccessState> {
emit(FailedState(e.toString()));
}
}
}
+26 -28
View File
@@ -96,35 +96,33 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
Future<void> changePassword(ChangePasswordEvent event, Emitter<AuthState> emit) async {
emit(LoadingForgetState());
try {
var response = await AuthenticationAPI.verifyOtp(
email: forgetEmailController.text, otpCode: forgetOtp.text);
if (response == true) {
await AuthenticationAPI.forgetPassword(
password: forgetPasswordController.text,
email: forgetEmailController.text);
_timer?.cancel();
emit(const TimerState(isButtonEnabled: true, remainingTime: 0));
emit(SuccessForgetState());
}
} on DioException catch (e) {
final errorData = e.response!.data;
String errorMessage = errorData['message'];
if (errorMessage == 'this email is not registered') {
validate = 'Invalid Credentials!';
emit(AuthInitialState());
} else if (errorMessage == "You entered wrong otp") {
forgetValidate = 'Wrong one time password.';
emit(AuthInitialState());
} else if (errorMessage == "OTP expired") {
forgetValidate = 'One time password has been expired.';
emit(AuthInitialState());
} else {
validate = '';
emit(AuthInitialState());
}
try {
var response = await AuthenticationAPI.verifyOtp(
email: forgetEmailController.text, otpCode: forgetOtp.text);
if (response == true) {
await AuthenticationAPI.forgetPassword(
password: forgetPasswordController.text, email: forgetEmailController.text);
_timer?.cancel();
emit(const TimerState(isButtonEnabled: true, remainingTime: 0));
emit(SuccessForgetState());
}
} on DioException catch (e) {
final errorData = e.response!.data;
String errorMessage = errorData['message'];
if (errorMessage == 'this email is not registered') {
validate = 'Invalid Credentials!';
emit(AuthInitialState());
} else if (errorMessage == "You entered wrong otp") {
forgetValidate = 'Wrong one time password.';
emit(AuthInitialState());
} else if (errorMessage == "OTP expired") {
forgetValidate = 'One time password has been expired.';
emit(AuthInitialState());
} else {
validate = '';
emit(AuthInitialState());
}
}
}
String? validateCode(String? value) {
+2 -8
View File
@@ -1,6 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.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/constants/assets.dart';
@@ -22,13 +22,7 @@ class CurtainToggle extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: ColorsManager.greyColor.withOpacity(0.2),
border: Border.all(color: ColorsManager.boxDivider),
),
padding: const EdgeInsets.all(16),
return DeviceControlsContainer(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
+36 -30
View File
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_web/pages/device_managment/all_devices/bloc/device_managment_bloc.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/constants/assets.dart';
@@ -53,30 +55,47 @@ class _DynamicTableState extends State<DynamicTable> {
@override
void didUpdateWidget(DynamicTable oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.data.length != widget.data.length) {
if (!_compareListOfLists(oldWidget.data, widget.data)) {
_initializeSelection();
}
}
bool _compareListOfLists(List<List<dynamic>> oldList, List<List<dynamic>> newList) {
// Check if the old and new lists are the same
if (oldList.length != newList.length) return false;
for (int i = 0; i < oldList.length; i++) {
if (oldList[i].length != newList[i].length) return false;
for (int j = 0; j < oldList[i].length; j++) {
if (oldList[i][j] != newList[i][j]) return false;
}
}
return true;
}
void _initializeSelection() {
_selectedRows = List<bool>.filled(widget.data.length, false);
_selectAll = false;
}
void _toggleSelectAll(bool? value) {
setState(() {
_selectAll = value ?? false;
_selectedRows = List<bool>.filled(widget.data.length, _selectAll);
});
widget.onSelectionChanged?.call(_selectedRows);
}
void _toggleRowSelection(int index) {
setState(() {
_selectedRows[index] = !_selectedRows[index];
_selectAll = _selectedRows.every((isSelected) => isSelected);
});
widget.onSelectionChanged?.call(_selectedRows);
context.read<DeviceManagementBloc>().add(UpdateSelection(_selectedRows));
}
void _toggleSelectAll(bool? value) {
setState(() {
_selectAll = value ?? false;
_selectedRows = List<bool>.filled(widget.data.length, _selectAll);
});
widget.onSelectionChanged?.call(_selectedRows);
context.read<DeviceManagementBloc>().add(UpdateSelection(_selectedRows));
}
@override
@@ -90,13 +109,11 @@ class _DynamicTableState extends State<DynamicTable> {
child: Column(
children: [
Container(
decoration: widget.headerDecoration ??
BoxDecoration(color: Colors.grey[200]),
decoration: widget.headerDecoration ?? BoxDecoration(color: Colors.grey[200]),
child: Row(
children: [
if (widget.withCheckBox) _buildSelectAllCheckbox(),
...widget.headers
.map((header) => _buildTableHeaderCell(header)),
...widget.headers.map((header) => _buildTableHeaderCell(header)),
],
),
),
@@ -117,14 +134,9 @@ class _DynamicTableState extends State<DynamicTable> {
),
Text(
// no password
widget.tableName == 'AccessManagement'
? 'No Password '
: 'No Devices',
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
color: ColorsManager.grayColor),
widget.tableName == 'AccessManagement' ? 'No Password ' : 'No Devices',
style:
Theme.of(context).textTheme.bodySmall!.copyWith(color: ColorsManager.grayColor),
)
],
),
@@ -143,12 +155,8 @@ class _DynamicTableState extends State<DynamicTable> {
final row = widget.data[index];
return Row(
children: [
if (widget.withCheckBox)
_buildRowCheckbox(
index, widget.size.height * 0.10),
...row.map((cell) => _buildTableCell(
cell.toString(),
widget.size.height * 0.10)),
if (widget.withCheckBox) _buildRowCheckbox(index, widget.size.height * 0.10),
...row.map((cell) => _buildTableCell(cell.toString(), widget.size.height * 0.10)),
],
);
},
@@ -173,9 +181,7 @@ class _DynamicTableState extends State<DynamicTable> {
),
child: Checkbox(
value: _selectAll,
onChanged: widget.withSelectAll && widget.data.isNotEmpty
? _toggleSelectAll
: null,
onChanged: widget.withSelectAll && widget.data.isNotEmpty ? _toggleSelectAll : null,
),
);
}
@@ -2,20 +2,21 @@ import 'package:flutter/material.dart';
import 'package:syncrow_web/utils/extension/build_context_x.dart';
class StatefulTextField extends StatefulWidget {
const StatefulTextField({
super.key,
required this.title,
this.hintText = 'Please enter',
required this.width,
this.elevation = 0,
required this.controller,
});
const StatefulTextField(
{super.key,
required this.title,
this.hintText = 'Please enter',
required this.width,
this.elevation = 0,
required this.controller,
this.onSubmitted});
final String title;
final String hintText;
final double width;
final double elevation;
final TextEditingController controller;
final Function? onSubmitted;
@override
State<StatefulTextField> createState() => _StatefulTextFieldState();
@@ -25,30 +26,31 @@ class _StatefulTextFieldState extends State<StatefulTextField> {
@override
Widget build(BuildContext context) {
return CustomTextField(
title: widget.title,
controller: widget.controller,
hintText: widget.hintText,
width: widget.width,
elevation: widget.elevation,
);
title: widget.title,
controller: widget.controller,
hintText: widget.hintText,
width: widget.width,
elevation: widget.elevation,
onSubmittedFun: widget.onSubmitted);
}
}
class CustomTextField extends StatelessWidget {
const CustomTextField({
super.key,
required this.title,
required this.controller,
this.hintText = 'Please enter',
required this.width,
this.elevation = 0,
});
const CustomTextField(
{super.key,
required this.title,
required this.controller,
this.hintText = 'Please enter',
required this.width,
this.elevation = 0,
this.onSubmittedFun});
final String title;
final TextEditingController controller;
final String hintText;
final double width;
final double elevation;
final Function? onSubmittedFun;
@override
Widget build(BuildContext context) {
@@ -81,10 +83,12 @@ class CustomTextField extends StatelessWidget {
decoration: InputDecoration(
hintText: hintText,
hintStyle: const TextStyle(fontSize: 12),
contentPadding:
const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
border: InputBorder.none,
),
onFieldSubmitted: (_) {
onSubmittedFun!();
},
),
),
),
@@ -15,8 +15,7 @@ import 'package:syncrow_web/utils/constants/assets.dart';
import 'package:syncrow_web/utils/extension/build_context_x.dart';
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
class AcDeviceBatchControlView extends StatelessWidget
with HelperResponsiveLayout {
class AcDeviceBatchControlView extends StatelessWidget with HelperResponsiveLayout {
const AcDeviceBatchControlView({super.key, required this.devicesIds});
final List<String> devicesIds;
@@ -27,8 +26,7 @@ class AcDeviceBatchControlView extends StatelessWidget
final isLarge = isLargeScreenSize(context);
final isMedium = isMediumScreenSize(context);
return BlocProvider(
create: (context) => AcBloc(deviceId: devicesIds.first)
..add(AcFetchBatchStatusEvent(devicesIds)),
create: (context) => AcBloc(deviceId: devicesIds.first)..add(AcFetchBatchStatusEvent(devicesIds)),
child: BlocBuilder<AcBloc, AcsState>(
builder: (context, state) {
if (state is ACStatusLoaded) {
@@ -66,6 +64,7 @@ class AcDeviceBatchControlView extends StatelessWidget
tempSet: state.status.tempSet,
code: 'temp_set',
devicesIds: devicesIds,
isBatch: true,
),
BatchAcMode(
value: state.status.acMode,
@@ -99,8 +98,7 @@ class AcDeviceBatchControlView extends StatelessWidget
),
Text(
'h',
style: context.textTheme.bodySmall!
.copyWith(color: ColorsManager.blackColor),
style: context.textTheme.bodySmall!.copyWith(color: ColorsManager.blackColor),
),
Text(
'30',
@@ -109,9 +107,7 @@ class AcDeviceBatchControlView extends StatelessWidget
fontWeight: FontWeight.bold,
),
),
Text('m',
style: context.textTheme.bodySmall!
.copyWith(color: ColorsManager.blackColor)),
Text('m', style: context.textTheme.bodySmall!.copyWith(color: ColorsManager.blackColor)),
IconButton(
onPressed: () {},
icon: const Icon(
@@ -133,7 +129,7 @@ class AcDeviceBatchControlView extends StatelessWidget
code: 'child_lock',
value: state.status.childLock,
label: 'Child Lock',
icon: state.status.childLock ? Assets.unlock : Assets.acLock,
icon: state.status.childLock ? Assets.acLock : Assets.unlock,
onChange: (value) {
context.read<AcBloc>().add(AcBatchControlEvent(
devicesIds: devicesIds,
@@ -147,8 +143,7 @@ class AcDeviceBatchControlView extends StatelessWidget
callFactoryReset: () {
context.read<AcBloc>().add(AcFactoryResetEvent(
deviceId: state.status.uuid,
factoryResetModel:
FactoryResetModel(devicesUuid: devicesIds),
factoryResetModel: FactoryResetModel(devicesUuid: devicesIds),
));
},
),
@@ -24,8 +24,7 @@ class AcDeviceControlsView extends StatelessWidget with HelperResponsiveLayout {
final isLarge = isLargeScreenSize(context);
final isMedium = isMediumScreenSize(context);
return BlocProvider(
create: (context) => AcBloc(deviceId: device.uuid!)
..add(AcFetchDeviceStatusEvent(device.uuid!)),
create: (context) => AcBloc(deviceId: device.uuid!)..add(AcFetchDeviceStatusEvent(device.uuid!)),
child: BlocBuilder<AcBloc, AcsState>(
builder: (context, state) {
if (state is ACStatusLoaded) {
@@ -98,8 +97,7 @@ class AcDeviceControlsView extends StatelessWidget with HelperResponsiveLayout {
),
Text(
'h',
style: context.textTheme.bodySmall!
.copyWith(color: ColorsManager.blackColor),
style: context.textTheme.bodySmall!.copyWith(color: ColorsManager.blackColor),
),
Text(
'30',
@@ -108,9 +106,7 @@ class AcDeviceControlsView extends StatelessWidget with HelperResponsiveLayout {
fontWeight: FontWeight.bold,
),
),
Text('m',
style: context.textTheme.bodySmall!
.copyWith(color: ColorsManager.blackColor)),
Text('m', style: context.textTheme.bodySmall!.copyWith(color: ColorsManager.blackColor)),
IconButton(
onPressed: () {},
icon: const Icon(
@@ -132,7 +128,7 @@ class AcDeviceControlsView extends StatelessWidget with HelperResponsiveLayout {
code: 'child_lock',
value: state.status.childLock,
label: 'Child Lock',
icon: state.status.childLock ? Assets.unlock : Assets.acLock,
icon: state.status.childLock ? Assets.acLock : Assets.unlock,
onChange: (value) {
context.read<AcBloc>().add(
AcControlEvent(
@@ -1,11 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/device_managment/ac/model/ac_model.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/constants/assets.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_bloc.dart';
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_event.dart';
import 'package:syncrow_web/pages/device_managment/ac/model/ac_model.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/constants/assets.dart';
class BatchAcMode extends StatelessWidget {
const BatchAcMode({
@@ -21,30 +22,20 @@ class BatchAcMode extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: ColorsManager.greyColor.withOpacity(0.2),
border: Border.all(color: ColorsManager.boxDivider),
),
padding: const EdgeInsets.all(16),
return DeviceControlsContainer(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
_buildIconContainer(context, TempModes.cold, Assets.freezing,
value == TempModes.cold),
_buildIconContainer(
context, TempModes.hot, Assets.acSun, value == TempModes.hot),
_buildIconContainer(context, TempModes.wind, Assets.acAirConditioner,
value == TempModes.wind),
_buildIconContainer(context, TempModes.cold, Assets.freezing, value == TempModes.cold),
_buildIconContainer(context, TempModes.hot, Assets.acSun, value == TempModes.hot),
_buildIconContainer(context, TempModes.wind, Assets.acAirConditioner, value == TempModes.wind),
],
),
);
}
Widget _buildIconContainer(
BuildContext context, TempModes mode, String assetPath, bool isSelected) {
Widget _buildIconContainer(BuildContext context, TempModes mode, String assetPath, bool isSelected) {
return Flexible(
child: GestureDetector(
onTap: () {
@@ -1,11 +1,13 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_bloc.dart';
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_event.dart';
import 'package:syncrow_web/pages/device_managment/shared/celciuse_symbol.dart';
import 'package:syncrow_web/pages/device_managment/shared/device_controls_container.dart';
import 'package:syncrow_web/pages/device_managment/shared/increament_decreament.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_bloc.dart';
class BatchCurrentTemp extends StatefulWidget {
const BatchCurrentTemp({
@@ -14,12 +16,14 @@ class BatchCurrentTemp extends StatefulWidget {
required this.devicesIds,
required this.currentTemp,
required this.tempSet,
this.isBatch,
});
final String code;
final List<String> devicesIds;
final int currentTemp;
final int tempSet;
final bool? isBatch;
@override
State<BatchCurrentTemp> createState() => _CurrentTempState();
@@ -67,49 +71,39 @@ class _CurrentTempState extends State<BatchCurrentTemp> {
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: ColorsManager.greyColor.withOpacity(0.2),
border: Border.all(color: ColorsManager.boxDivider),
),
padding: const EdgeInsets.all(16),
return DeviceControlsContainer(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Current Temperature',
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(color: Colors.grey),
),
const SizedBox(
height: 5,
),
Row(
children: [
Text(
(widget.currentTemp > 99
? widget.currentTemp / 10
: widget.currentTemp)
.toString(),
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(color: Colors.grey),
),
const CelsiusSymbol(
color: Colors.grey,
)
],
),
],
),
widget.isBatch == true
? Text(
'Set Temperature',
style: Theme.of(context).textTheme.bodySmall!.copyWith(color: Colors.grey),
)
: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Current Temperature',
style: Theme.of(context).textTheme.bodySmall!.copyWith(color: Colors.grey),
),
const SizedBox(
height: 5,
),
Row(
children: [
Text(
(widget.currentTemp > 99 ? widget.currentTemp / 10 : widget.currentTemp).toString(),
style: Theme.of(context).textTheme.bodySmall!.copyWith(color: Colors.grey),
),
const CelsiusSymbol(
color: Colors.grey,
)
],
),
],
),
const Spacer(),
IncrementDecrementWidget(
value: _adjustedValue.toString(),
@@ -1,11 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/device_managment/ac/model/ac_model.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/constants/assets.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_bloc.dart';
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_event.dart';
import 'package:syncrow_web/pages/device_managment/ac/model/ac_model.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/constants/assets.dart';
class BatchFanSpeedControl extends StatelessWidget {
const BatchFanSpeedControl({
@@ -21,23 +22,16 @@ class BatchFanSpeedControl extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: ColorsManager.greyColor.withOpacity(0.2),
border: Border.all(color: ColorsManager.boxDivider),
),
padding: const EdgeInsets.all(8),
return DeviceControlsContainer(
padding: 8,
child: Column(
children: [
Wrap(
runSpacing: 8,
spacing: 8,
children: [
_buildIconContainer(context, FanSpeeds.auto, Assets.acFanAuto,
value == FanSpeeds.auto),
_buildIconContainer(context, FanSpeeds.low, Assets.acFanLow,
value == FanSpeeds.low),
_buildIconContainer(context, FanSpeeds.auto, Assets.acFanAuto, value == FanSpeeds.auto),
_buildIconContainer(context, FanSpeeds.low, Assets.acFanLow, value == FanSpeeds.low),
],
),
const SizedBox(height: 8),
@@ -45,10 +39,8 @@ class BatchFanSpeedControl extends StatelessWidget {
runSpacing: 8,
spacing: 8,
children: [
_buildIconContainer(context, FanSpeeds.middle, Assets.acFanMiddle,
value == FanSpeeds.middle),
_buildIconContainer(context, FanSpeeds.high, Assets.acFanHigh,
value == FanSpeeds.high),
_buildIconContainer(context, FanSpeeds.middle, Assets.acFanMiddle, value == FanSpeeds.middle),
_buildIconContainer(context, FanSpeeds.high, Assets.acFanHigh, value == FanSpeeds.high),
],
)
],
@@ -56,8 +48,7 @@ class BatchFanSpeedControl extends StatelessWidget {
);
}
Widget _buildIconContainer(BuildContext context, FanSpeeds speed,
String assetPath, bool isSelected) {
Widget _buildIconContainer(BuildContext context, FanSpeeds speed, String assetPath, bool isSelected) {
return GestureDetector(
onTap: () {
context.read<AcBloc>().add(
@@ -1,11 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/device_managment/ac/model/ac_model.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/constants/assets.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_bloc.dart';
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_event.dart';
import 'package:syncrow_web/pages/device_managment/ac/model/ac_model.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/constants/assets.dart';
class AcMode extends StatelessWidget {
const AcMode({
@@ -21,30 +22,20 @@ class AcMode extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: ColorsManager.greyColor.withOpacity(0.2),
border: Border.all(color: ColorsManager.boxDivider),
),
padding: const EdgeInsets.all(16),
return DeviceControlsContainer(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
_buildIconContainer(context, TempModes.cold, Assets.freezing,
value == TempModes.cold),
_buildIconContainer(
context, TempModes.hot, Assets.acSun, value == TempModes.hot),
_buildIconContainer(context, TempModes.wind, Assets.acAirConditioner,
value == TempModes.wind),
_buildIconContainer(context, TempModes.cold, Assets.freezing, value == TempModes.cold),
_buildIconContainer(context, TempModes.hot, Assets.acSun, value == TempModes.hot),
_buildIconContainer(context, TempModes.wind, Assets.acAirConditioner, value == TempModes.wind),
],
),
);
}
Widget _buildIconContainer(
BuildContext context, TempModes mode, String assetPath, bool isSelected) {
Widget _buildIconContainer(BuildContext context, TempModes mode, String assetPath, bool isSelected) {
return Flexible(
child: GestureDetector(
onTap: () {
@@ -1,9 +1,9 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_bloc.dart';
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_event.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/constants/assets.dart';
@@ -25,13 +25,7 @@ class AcToggle extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: ColorsManager.greyColor.withOpacity(0.2),
border: Border.all(color: ColorsManager.boxDivider),
),
padding: const EdgeInsets.all(16),
return DeviceControlsContainer(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -1,11 +1,13 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_bloc.dart';
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_event.dart';
import 'package:syncrow_web/pages/device_managment/shared/celciuse_symbol.dart';
import 'package:syncrow_web/pages/device_managment/shared/device_controls_container.dart';
import 'package:syncrow_web/pages/device_managment/shared/increament_decreament.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_bloc.dart';
class CurrentTemp extends StatefulWidget {
const CurrentTemp({
@@ -67,13 +69,7 @@ class _CurrentTempState extends State<CurrentTemp> {
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: ColorsManager.greyColor.withOpacity(0.2),
border: Border.all(color: ColorsManager.boxDivider),
),
padding: const EdgeInsets.all(16),
return DeviceControlsContainer(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -83,10 +79,7 @@ class _CurrentTempState extends State<CurrentTemp> {
children: [
Text(
'Current Temperature',
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(color: Colors.grey),
style: Theme.of(context).textTheme.bodySmall!.copyWith(color: Colors.grey),
),
const SizedBox(
height: 5,
@@ -94,14 +87,8 @@ class _CurrentTempState extends State<CurrentTemp> {
Row(
children: [
Text(
(widget.currentTemp > 99
? widget.currentTemp / 10
: widget.currentTemp)
.toString(),
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(color: Colors.grey),
(widget.currentTemp > 99 ? widget.currentTemp / 10 : widget.currentTemp).toString(),
style: Theme.of(context).textTheme.bodySmall!.copyWith(color: Colors.grey),
),
const CelsiusSymbol(
color: Colors.grey,
@@ -1,11 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/device_managment/ac/model/ac_model.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/constants/assets.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_bloc.dart';
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_event.dart';
import 'package:syncrow_web/pages/device_managment/ac/model/ac_model.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/constants/assets.dart';
class FanSpeedControl extends StatelessWidget {
const FanSpeedControl({
@@ -21,23 +22,15 @@ class FanSpeedControl extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: ColorsManager.greyColor.withOpacity(0.2),
border: Border.all(color: ColorsManager.boxDivider),
),
padding: const EdgeInsets.all(8),
return DeviceControlsContainer(
child: Column(
children: [
Wrap(
runSpacing: 8,
spacing: 8,
children: [
_buildIconContainer(context, FanSpeeds.auto, Assets.acFanAuto,
value == FanSpeeds.auto),
_buildIconContainer(context, FanSpeeds.low, Assets.acFanLow,
value == FanSpeeds.low),
_buildIconContainer(context, FanSpeeds.auto, Assets.acFanAuto, value == FanSpeeds.auto),
_buildIconContainer(context, FanSpeeds.low, Assets.acFanLow, value == FanSpeeds.low),
],
),
const SizedBox(height: 8),
@@ -45,10 +38,8 @@ class FanSpeedControl extends StatelessWidget {
runSpacing: 8,
spacing: 8,
children: [
_buildIconContainer(context, FanSpeeds.middle, Assets.acFanMiddle,
value == FanSpeeds.middle),
_buildIconContainer(context, FanSpeeds.high, Assets.acFanHigh,
value == FanSpeeds.high),
_buildIconContainer(context, FanSpeeds.middle, Assets.acFanMiddle, value == FanSpeeds.middle),
_buildIconContainer(context, FanSpeeds.high, Assets.acFanHigh, value == FanSpeeds.high),
],
)
],
@@ -56,8 +47,7 @@ class FanSpeedControl extends StatelessWidget {
);
}
Widget _buildIconContainer(BuildContext context, FanSpeeds speed,
String assetPath, bool isSelected) {
Widget _buildIconContainer(BuildContext context, FanSpeeds speed, String assetPath, bool isSelected) {
return GestureDetector(
onTap: () {
context.read<AcBloc>().add(
@@ -6,8 +6,7 @@ import 'package:syncrow_web/services/devices_mang_api.dart';
part 'device_managment_event.dart';
part 'device_managment_state.dart';
class DeviceManagementBloc
extends Bloc<DeviceManagementEvent, DeviceManagementState> {
class DeviceManagementBloc extends Bloc<DeviceManagementEvent, DeviceManagementState> {
int _selectedIndex = 0;
List<AllDevicesModel> _devices = [];
int _onlineCount = 0;
@@ -16,6 +15,9 @@ class DeviceManagementBloc
List<AllDevicesModel> _selectedDevices = [];
List<AllDevicesModel> _filteredDevices = [];
String productName = '';
String? currentCommunity;
String? currentUnitName;
String? currentProductName;
DeviceManagementBloc() : super(DeviceManagementInitial()) {
on<FetchDevices>(_onFetchDevices);
@@ -28,8 +30,7 @@ class DeviceManagementBloc
on<UpdateSelection>(_onUpdateSelection);
}
Future<void> _onFetchDevices(
FetchDevices event, Emitter<DeviceManagementState> emit) async {
Future<void> _onFetchDevices(FetchDevices event, Emitter<DeviceManagementState> emit) async {
emit(DeviceManagementLoading());
try {
final devices = await DevicesManagementApi().fetchDevices();
@@ -51,8 +52,7 @@ class DeviceManagementBloc
}
}
void _onFilterDevices(
FilterDevices event, Emitter<DeviceManagementState> emit) async {
void _onFilterDevices(FilterDevices event, Emitter<DeviceManagementState> emit) async {
if (_devices.isNotEmpty) {
_filteredDevices = List.from(_devices.where((device) {
switch (event.filter) {
@@ -83,8 +83,7 @@ class DeviceManagementBloc
}
}
Future<void> _onResetFilters(
ResetFilters event, Emitter<DeviceManagementState> emit) async {
Future<void> _onResetFilters(ResetFilters event, Emitter<DeviceManagementState> emit) async {
productName = '';
_selectedDevices.clear();
_filteredDevices = List.from(_devices);
@@ -100,8 +99,7 @@ class DeviceManagementBloc
));
}
void _onResetSelectedDevices(
ResetSelectedDevices event, Emitter<DeviceManagementState> emit) {
void _onResetSelectedDevices(ResetSelectedDevices event, Emitter<DeviceManagementState> emit) {
_selectedDevices.clear();
if (state is DeviceManagementLoaded) {
@@ -127,14 +125,12 @@ class DeviceManagementBloc
}
}
void _onSelectedFilterChanged(
SelectedFilterChanged event, Emitter<DeviceManagementState> emit) {
void _onSelectedFilterChanged(SelectedFilterChanged event, Emitter<DeviceManagementState> emit) {
_selectedIndex = event.selectedIndex;
add(FilterDevices(_getFilterFromIndex(_selectedIndex)));
}
void _onSelectDevice(
SelectDevice event, Emitter<DeviceManagementState> emit) {
void _onSelectDevice(SelectDevice event, Emitter<DeviceManagementState> emit) {
final selectedUuid = event.selectedDevice.uuid;
if (_selectedDevices.any((device) => device.uuid == selectedUuid)) {
@@ -145,8 +141,7 @@ class DeviceManagementBloc
List<AllDevicesModel> clonedSelectedDevices = List.from(_selectedDevices);
bool isControlButtonEnabled =
_checkIfControlButtonEnabled(clonedSelectedDevices);
bool isControlButtonEnabled = _checkIfControlButtonEnabled(clonedSelectedDevices);
if (state is DeviceManagementLoaded) {
emit(DeviceManagementLoaded(
@@ -155,8 +150,7 @@ class DeviceManagementBloc
onlineCount: _onlineCount,
offlineCount: _offlineCount,
lowBatteryCount: _lowBatteryCount,
selectedDevice:
clonedSelectedDevices.isNotEmpty ? clonedSelectedDevices : null,
selectedDevice: clonedSelectedDevices.isNotEmpty ? clonedSelectedDevices : null,
isControlButtonEnabled: isControlButtonEnabled,
));
} else if (state is DeviceManagementFiltered) {
@@ -166,15 +160,13 @@ class DeviceManagementBloc
onlineCount: _onlineCount,
offlineCount: _offlineCount,
lowBatteryCount: _lowBatteryCount,
selectedDevice:
clonedSelectedDevices.isNotEmpty ? clonedSelectedDevices : null,
selectedDevice: clonedSelectedDevices.isNotEmpty ? clonedSelectedDevices : null,
isControlButtonEnabled: isControlButtonEnabled,
));
}
}
void _onUpdateSelection(
UpdateSelection event, Emitter<DeviceManagementState> emit) {
void _onUpdateSelection(UpdateSelection event, Emitter<DeviceManagementState> emit) {
List<AllDevicesModel> selectedDevices = [];
List<AllDevicesModel> devicesToSelectFrom = [];
@@ -217,8 +209,7 @@ class DeviceManagementBloc
bool _checkIfControlButtonEnabled(List<AllDevicesModel> selectedDevices) {
if (selectedDevices.length > 1) {
final productTypes =
selectedDevices.map((device) => device.productType).toSet();
final productTypes = selectedDevices.map((device) => device.productType).toSet();
return productTypes.length == 1;
} else if (selectedDevices.length == 1) {
return true;
@@ -229,10 +220,8 @@ class DeviceManagementBloc
void _calculateDeviceCounts() {
_onlineCount = _devices.where((device) => device.online == true).length;
_offlineCount = _devices.where((device) => device.online == false).length;
_lowBatteryCount = _devices
.where((device) =>
device.batteryLevel != null && device.batteryLevel! < 20)
.length;
_lowBatteryCount =
_devices.where((device) => device.batteryLevel != null && device.batteryLevel! < 20).length;
}
String _getFilterFromIndex(int index) {
@@ -248,14 +237,25 @@ class DeviceManagementBloc
}
}
void _onSearchDevices(
SearchDevices event, Emitter<DeviceManagementState> emit) {
void _onSearchDevices(SearchDevices event, Emitter<DeviceManagementState> emit) {
if (event.productName == currentProductName &&
event.community == currentCommunity &&
event.unitName == currentUnitName) {
return;
}
currentProductName = event.productName;
currentCommunity = event.community;
currentUnitName = event.unitName;
if ((event.community == null || event.community!.isEmpty) &&
(event.unitName == null || event.unitName!.isEmpty) &&
(event.productName == null || event.productName!.isEmpty)) {
productName = '';
if (state is DeviceManagementFiltered) {
add(FilterDevices(_getFilterFromIndex(_selectedIndex)));
} else {
return;
}
}
@@ -263,38 +263,22 @@ class DeviceManagementBloc
List<AllDevicesModel> devicesToSearch = _filteredDevices;
if (devicesToSearch.isNotEmpty) {
_selectedDevices.clear();
_selectedIndex = _selectedIndex;
final filteredDevices = devicesToSearch.where((device) {
final matchesCommunity = event.community == null ||
event.community!.isEmpty ||
(device.room?.name
?.toLowerCase()
.contains(event.community!.toLowerCase()) ??
false);
(device.room?.name?.toLowerCase().contains(event.community!.toLowerCase()) ?? false);
final matchesUnit = event.unitName == null ||
event.unitName!.isEmpty ||
(device.unit?.name
?.toLowerCase()
.contains(event.unitName!.toLowerCase()) ??
false);
(device.unit?.name?.toLowerCase().contains(event.unitName!.toLowerCase()) ?? false);
final matchesProductName = event.productName == null ||
event.productName!.isEmpty ||
(device.name
?.toLowerCase()
.contains(event.productName!.toLowerCase()) ??
false);
(device.name?.toLowerCase().contains(event.productName!.toLowerCase()) ?? false);
final matchesDeviceName = event.productName == null ||
event.productName!.isEmpty ||
(device.categoryName
?.toLowerCase()
.contains(event.productName!.toLowerCase()) ??
(device.categoryName?.toLowerCase().contains(event.productName!.toLowerCase()) ??
false);
return matchesCommunity &&
matchesUnit &&
(matchesProductName || matchesDeviceName);
return matchesCommunity && matchesUnit && (matchesProductName || matchesDeviceName);
}).toList();
emit(DeviceManagementFiltered(
@@ -1,14 +1,14 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/device_managment/shared/device_batch_control_dialog.dart';
import 'package:syncrow_web/utils/extension/build_context_x.dart';
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
import 'package:syncrow_web/pages/common/custom_table.dart';
import 'package:syncrow_web/pages/common/filter/filter_widget.dart';
import 'package:syncrow_web/pages/device_managment/all_devices/bloc/device_managment_bloc.dart';
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
import 'package:syncrow_web/pages/device_managment/shared/device_control_dialog.dart';
import 'package:syncrow_web/pages/device_managment/all_devices/widgets/device_search_filters.dart';
import 'package:syncrow_web/pages/device_managment/shared/device_batch_control_dialog.dart';
import 'package:syncrow_web/pages/device_managment/shared/device_control_dialog.dart';
import 'package:syncrow_web/utils/extension/build_context_x.dart';
import 'package:syncrow_web/utils/format_date_time.dart';
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
import 'package:syncrow_web/utils/style.dart';
@@ -37,8 +37,7 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
offlineCount = state.offlineCount;
lowBatteryCount = state.lowBatteryCount;
isControlButtonEnabled = state.isControlButtonEnabled;
selectedDevices = state.selectedDevice ??
context.read<DeviceManagementBloc>().selectedDevices;
selectedDevices = state.selectedDevice ?? [];
} else if (state is DeviceManagementFiltered) {
devicesToShow = state.filteredDevices;
selectedIndex = state.selectedIndex;
@@ -46,14 +45,12 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
offlineCount = state.offlineCount;
lowBatteryCount = state.lowBatteryCount;
isControlButtonEnabled = state.isControlButtonEnabled;
selectedDevices = state.selectedDevice ??
context.read<DeviceManagementBloc>().selectedDevices;
selectedDevices = state.selectedDevice ?? [];
} else if (state is DeviceManagementInitial) {
devicesToShow = [];
selectedIndex = 0;
isControlButtonEnabled = false;
}
final tabs = [
'All',
'Online ($onlineCount)',
@@ -61,15 +58,12 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
'Low Battery ($lowBatteryCount)',
];
final buttonLabel =
(selectedDevices.length > 1) ? 'Batch Control' : 'Control';
final buttonLabel = (selectedDevices.length > 1) ? 'Batch Control' : 'Control';
return Column(
children: [
Container(
padding: isLargeScreenSize(context)
? const EdgeInsets.all(30)
: const EdgeInsets.all(15),
padding: isLargeScreenSize(context) ? const EdgeInsets.all(30) : const EdgeInsets.all(15),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -78,9 +72,7 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
tabs: tabs,
selectedIndex: selectedIndex,
onTabChanged: (index) {
context
.read<DeviceManagementBloc>()
.add(SelectedFilterChanged(index));
context.read<DeviceManagementBloc>().add(SelectedFilterChanged(index));
},
),
const SizedBox(height: 20),
@@ -102,14 +94,11 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
),
);
} else if (selectedDevices.length > 1) {
final productTypes = selectedDevices
.map((device) => device.productType)
.toSet();
final productTypes = selectedDevices.map((device) => device.productType).toSet();
if (productTypes.length == 1) {
showDialog(
context: context,
builder: (context) =>
DeviceBatchControlDialog(
builder: (context) => DeviceBatchControlDialog(
devices: selectedDevices,
),
);
@@ -123,9 +112,7 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 12,
color: isControlButtonEnabled
? Colors.white
: Colors.grey,
color: isControlButtonEnabled ? Colors.white : Colors.grey,
),
),
),
@@ -136,17 +123,13 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
),
Expanded(
child: Padding(
padding: isLargeScreenSize(context)
? const EdgeInsets.all(30)
: const EdgeInsets.all(15),
padding: isLargeScreenSize(context) ? const EdgeInsets.all(30) : const EdgeInsets.all(15),
child: DynamicTable(
withSelectAll: true,
cellDecoration: containerDecoration,
onRowSelected: (index, isSelected, row) {
final selectedDevice = devicesToShow[index];
context
.read<DeviceManagementBloc>()
.add(SelectDevice(selectedDevice));
context.read<DeviceManagementBloc>().add(SelectDevice(selectedDevice));
},
withCheckBox: true,
size: context.screenSize,
@@ -169,26 +152,17 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
device.uuid ?? '',
device.unit?.name ?? '',
device.room?.name ?? '',
device.batteryLevel != null
? '${device.batteryLevel}%'
: '-',
formatDateTime(DateTime.fromMillisecondsSinceEpoch(
(device.createTime ?? 0) * 1000)),
device.batteryLevel != null ? '${device.batteryLevel}%' : '-',
formatDateTime(DateTime.fromMillisecondsSinceEpoch((device.createTime ?? 0) * 1000)),
device.online == true ? 'Online' : 'Offline',
formatDateTime(DateTime.fromMillisecondsSinceEpoch(
(device.updateTime ?? 0) * 1000)),
formatDateTime(DateTime.fromMillisecondsSinceEpoch((device.updateTime ?? 0) * 1000)),
];
}).toList(),
onSelectionChanged: (selectedRows) {
context
.read<DeviceManagementBloc>()
.add(UpdateSelection(selectedRows));
context.read<DeviceManagementBloc>().add(UpdateSelection(selectedRows));
},
initialSelectedIds: context
.read<DeviceManagementBloc>()
.selectedDevices
.map((device) => device.uuid!)
.toList(),
initialSelectedIds:
context.read<DeviceManagementBloc>().selectedDevices.map((device) => device.uuid!).toList(),
isEmpty: devicesToShow.isEmpty,
),
),
@@ -12,8 +12,7 @@ class DeviceSearchFilters extends StatefulWidget {
State<DeviceSearchFilters> createState() => _DeviceSearchFiltersState();
}
class _DeviceSearchFiltersState extends State<DeviceSearchFilters>
with HelperResponsiveLayout {
class _DeviceSearchFiltersState extends State<DeviceSearchFilters> with HelperResponsiveLayout {
final TextEditingController communityController = TextEditingController();
final TextEditingController unitNameController = TextEditingController();
final TextEditingController productNameController = TextEditingController();
@@ -35,8 +34,7 @@ class _DeviceSearchFiltersState extends State<DeviceSearchFilters>
const SizedBox(width: 20),
_buildSearchField("Unit Name", unitNameController, 200),
const SizedBox(width: 20),
_buildSearchField(
"Device Name / Product Name", productNameController, 300),
_buildSearchField("Device Name / Product Name", productNameController, 300),
const SizedBox(width: 20),
_buildSearchResetButtons(),
],
@@ -45,22 +43,34 @@ class _DeviceSearchFiltersState extends State<DeviceSearchFilters>
spacing: 20,
runSpacing: 10,
children: [
_buildSearchField("Community", communityController, 200),
_buildSearchField(
"Community",
communityController,
200,
),
_buildSearchField("Unit Name", unitNameController, 200),
_buildSearchField(
"Device Name / Product Name", productNameController, 300),
"Device Name / Product Name",
productNameController,
300,
),
_buildSearchResetButtons(),
],
);
}
Widget _buildSearchField(
String title, TextEditingController controller, double width) {
Widget _buildSearchField(String title, TextEditingController controller, double width) {
return StatefulTextField(
title: title,
width: width,
elevation: 2,
controller: controller,
onSubmitted: () {
context.read<DeviceManagementBloc>().add(SearchDevices(
productName: productNameController.text,
unitName: unitNameController.text,
));
},
);
}
@@ -1,8 +1,9 @@
import 'dart:async';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/event.dart';
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/state.dart';
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/ceiling_event.dart';
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/ceiling_state.dart';
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/model/ceiling_sensor_model.dart';
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/model/help_description.dart';
import 'package:syncrow_web/services/devices_mang_api.dart';
@@ -27,8 +28,7 @@ class CeilingSensorBloc extends Bloc<CeilingSensorEvent, CeilingSensorState> {
CeilingInitialEvent event, Emitter<CeilingSensorState> emit) async {
emit(CeilingLoadingInitialState());
try {
var response =
await DevicesManagementApi().getDeviceStatus(event.deviceId);
var response = await DevicesManagementApi().getDeviceStatus(event.deviceId);
deviceStatus = CeilingSensorModel.fromJson(response.status);
emit(CeilingUpdateState(ceilingSensorModel: deviceStatus));
// _listenToChanges();
@@ -57,8 +57,7 @@ class CeilingSensorBloc extends Bloc<CeilingSensorEvent, CeilingSensorState> {
// } catch (_) {}
// }
void _changeValue(
CeilingChangeValueEvent event, Emitter<CeilingSensorState> emit) async {
void _changeValue(CeilingChangeValueEvent event, Emitter<CeilingSensorState> emit) async {
emit(CeilingLoadingNewSate(ceilingSensorModel: deviceStatus));
if (event.code == 'sensitivity') {
deviceStatus.sensitivity = event.value;
@@ -123,8 +122,7 @@ class CeilingSensorBloc extends Bloc<CeilingSensorEvent, CeilingSensorState> {
try {
late bool response;
if (isBatch) {
response = await DevicesManagementApi()
.deviceBatchControl(deviceId, code, value);
response = await DevicesManagementApi().deviceBatchControl(deviceId, code, value);
} else {
response = await DevicesManagementApi()
.deviceControl(deviceId, Status(code: code, value: value));
@@ -145,17 +143,19 @@ class CeilingSensorBloc extends Bloc<CeilingSensorEvent, CeilingSensorState> {
});
}
FutureOr<void> _getDeviceReports(GetCeilingDeviceReportsEvent event,
Emitter<CeilingSensorState> emit) async {
FutureOr<void> _getDeviceReports(
GetCeilingDeviceReportsEvent event, Emitter<CeilingSensorState> emit) async {
if (event.code.isEmpty) {
emit(ShowCeilingDescriptionState(description: reportString));
return;
} else {
emit(CeilingReportsLoadingState());
// final from = DateTime.now().subtract(const Duration(days: 30)).millisecondsSinceEpoch;
// final to = DateTime.now().millisecondsSinceEpoch;
try {
await DevicesManagementApi.getDeviceReports(deviceId, event.code)
.then((value) {
// await DevicesManagementApi.getDeviceReportsByDate(deviceId, event.code, from.toString(), to.toString())
await DevicesManagementApi.getDeviceReports(deviceId, event.code).then((value) {
emit(CeilingReportsState(deviceReport: value));
});
} catch (e) {
@@ -165,23 +165,19 @@ class CeilingSensorBloc extends Bloc<CeilingSensorEvent, CeilingSensorState> {
}
}
void _showDescription(
ShowCeilingDescriptionEvent event, Emitter<CeilingSensorState> emit) {
void _showDescription(ShowCeilingDescriptionEvent event, Emitter<CeilingSensorState> emit) {
emit(ShowCeilingDescriptionState(description: event.description));
}
void _backToGridView(
BackToCeilingGridViewEvent event, Emitter<CeilingSensorState> emit) {
void _backToGridView(BackToCeilingGridViewEvent event, Emitter<CeilingSensorState> emit) {
emit(CeilingUpdateState(ceilingSensorModel: deviceStatus));
}
FutureOr<void> _fetchCeilingSensorBatchControl(
CeilingFetchDeviceStatusEvent event,
Emitter<CeilingSensorState> emit) async {
CeilingFetchDeviceStatusEvent event, Emitter<CeilingSensorState> emit) async {
emit(CeilingLoadingInitialState());
try {
var response =
await DevicesManagementApi().getBatchStatus(event.devicesIds);
var response = await DevicesManagementApi().getBatchStatus(event.devicesIds);
deviceStatus = CeilingSensorModel.fromJson(response.status);
emit(CeilingUpdateState(ceilingSensorModel: deviceStatus));
} catch (e) {
@@ -46,22 +46,19 @@ class CeilingSensorModel {
_spaceType = getSpaceType(status.value ?? 'none');
break;
case 'sensitivity':
_sensitivity = status.value is int
? status.value
: int.tryParse(status.value ?? '1') ?? 1;
_sensitivity =
status.value is int ? status.value : int.tryParse(status.value ?? '1') ?? 1;
break;
case 'checking_result':
_checkingResult = status.value ?? '';
break;
case 'presence_range':
_presenceRange = status.value is int
? status.value
: int.tryParse(status.value ?? '0') ?? 0;
_presenceRange =
status.value is int ? status.value : int.tryParse(status.value ?? '0') ?? 0;
break;
case 'sports_para':
_sportsPara = status.value is int
? status.value
: int.tryParse(status.value ?? '0') ?? 0;
_sportsPara =
status.value is int ? status.value : int.tryParse(status.value ?? '0') ?? 0;
break;
case 'body_movement':
_bodyMovement = status.value ?? '';
@@ -70,9 +67,7 @@ class CeilingSensorModel {
_noBodyTime = status.value ?? 'none';
break;
case 'moving_max_dis':
_maxDis = status.value is int
? status.value
: int.tryParse(status.value ?? '0') ?? 0;
_maxDis = status.value is int ? status.value : int.tryParse(status.value ?? '0') ?? 0;
break;
}
}
@@ -1,9 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart';
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/bloc.dart';
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/event.dart';
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/state.dart';
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/ceiling_bloc.dart';
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/ceiling_event.dart';
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/ceiling_state.dart';
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/model/ceiling_sensor_model.dart';
import 'package:syncrow_web/pages/device_managment/shared/batch_control/factory_reset.dart';
import 'package:syncrow_web/pages/device_managment/shared/batch_control/firmware_update.dart';
@@ -12,8 +12,7 @@ import 'package:syncrow_web/pages/device_managment/shared/sensors_widgets/presen
import 'package:syncrow_web/pages/device_managment/shared/sensors_widgets/presense_nobody_time.dart';
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
class CeilingSensorBatchControlView extends StatelessWidget
with HelperResponsiveLayout {
class CeilingSensorBatchControlView extends StatelessWidget with HelperResponsiveLayout {
const CeilingSensorBatchControlView({super.key, required this.devicesIds});
final List<String> devicesIds;
@@ -28,12 +27,11 @@ class CeilingSensorBatchControlView extends StatelessWidget
..add(CeilingFetchDeviceStatusEvent(devicesIds)),
child: BlocBuilder<CeilingSensorBloc, CeilingSensorState>(
builder: (context, state) {
if (state is CeilingLoadingInitialState ||
state is CeilingReportsLoadingState) {
if (state is CeilingLoadingInitialState || state is CeilingReportsLoadingState) {
return const Center(child: CircularProgressIndicator());
} else if (state is CeilingUpdateState) {
return _buildGridView(context, state.ceilingSensorModel,
isExtraLarge, isLarge, isMedium);
return _buildGridView(
context, state.ceilingSensorModel, isExtraLarge, isLarge, isMedium);
}
return const Center(child: Text('Error fetching status'));
},
@@ -41,8 +39,8 @@ class CeilingSensorBatchControlView extends StatelessWidget
);
}
Widget _buildGridView(BuildContext context, CeilingSensorModel model,
bool isExtraLarge, bool isLarge, bool isMedium) {
Widget _buildGridView(BuildContext context, CeilingSensorModel model, bool isExtraLarge,
bool isLarge, bool isMedium) {
return GridView(
padding: const EdgeInsets.symmetric(horizontal: 50),
shrinkWrap: true,
@@ -118,8 +116,7 @@ class CeilingSensorBatchControlView extends StatelessWidget
context.read<CeilingSensorBloc>().add(
CeilingFactoryResetEvent(
devicesId: devicesIds.first,
factoryResetModel:
FactoryResetModel(devicesUuid: devicesIds),
factoryResetModel: FactoryResetModel(devicesUuid: devicesIds),
),
);
},
@@ -1,9 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/bloc.dart';
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/event.dart';
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/state.dart';
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/ceiling_bloc.dart';
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/ceiling_event.dart';
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/ceiling_state.dart';
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/model/ceiling_sensor_model.dart';
import 'package:syncrow_web/pages/device_managment/shared/sensors_widgets/presence_display_data.dart';
import 'package:syncrow_web/pages/device_managment/shared/sensors_widgets/presence_space_type.dart';
@@ -16,8 +16,7 @@ import 'package:syncrow_web/pages/device_managment/shared/table/report_table.dar
import 'package:syncrow_web/utils/constants/assets.dart';
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
class CeilingSensorControlsView extends StatelessWidget
with HelperResponsiveLayout {
class CeilingSensorControlsView extends StatelessWidget with HelperResponsiveLayout {
const CeilingSensorControlsView({super.key, required this.device});
final AllDevicesModel device;
@@ -32,35 +31,29 @@ class CeilingSensorControlsView extends StatelessWidget
..add(CeilingInitialEvent(device.uuid ?? '')),
child: BlocBuilder<CeilingSensorBloc, CeilingSensorState>(
builder: (context, state) {
if (state is CeilingLoadingInitialState ||
state is CeilingReportsLoadingState) {
if (state is CeilingLoadingInitialState || state is CeilingReportsLoadingState) {
return const Center(child: CircularProgressIndicator());
} else if (state is CeilingUpdateState) {
return _buildGridView(context, state.ceilingSensorModel,
isExtraLarge, isLarge, isMedium);
return _buildGridView(
context, state.ceilingSensorModel, isExtraLarge, isLarge, isMedium);
} else if (state is CeilingReportsState) {
return ReportsTable(
report: state.deviceReport,
onRowTap: (index) {},
onClose: () {
context
.read<CeilingSensorBloc>()
.add(BackToCeilingGridViewEvent());
context.read<CeilingSensorBloc>().add(BackToCeilingGridViewEvent());
},
);
} else if (state is ShowCeilingDescriptionState) {
return DescriptionView(
description: state.description,
onClose: () {
context
.read<CeilingSensorBloc>()
.add(BackToCeilingGridViewEvent());
context.read<CeilingSensorBloc>().add(BackToCeilingGridViewEvent());
},
);
} else if (state is CeilingReportsFailedState) {
final model = context.read<CeilingSensorBloc>().deviceStatus;
return _buildGridView(
context, model, isExtraLarge, isLarge, isMedium);
return _buildGridView(context, model, isExtraLarge, isLarge, isMedium);
}
return const Center(child: Text('Error fetching status'));
},
@@ -68,8 +61,8 @@ class CeilingSensorControlsView extends StatelessWidget
);
}
Widget _buildGridView(BuildContext context, CeilingSensorModel model,
bool isExtraLarge, bool isLarge, bool isMedium) {
Widget _buildGridView(BuildContext context, CeilingSensorModel model, bool isExtraLarge,
bool isLarge, bool isMedium) {
return GridView(
padding: const EdgeInsets.symmetric(horizontal: 50),
shrinkWrap: true,
@@ -150,8 +143,8 @@ class CeilingSensorControlsView extends StatelessWidget
),
GestureDetector(
onTap: () {
context.read<CeilingSensorBloc>().add(GetCeilingDeviceReportsEvent(
code: 'presence_state', deviceUuid: device.uuid!));
context.read<CeilingSensorBloc>().add(
GetCeilingDeviceReportsEvent(code: 'presence_state', deviceUuid: device.uuid!));
},
child: const PresenceStaticWidget(
icon: Assets.illuminanceRecordIcon,
@@ -160,8 +153,9 @@ class CeilingSensorControlsView extends StatelessWidget
),
GestureDetector(
onTap: () {
context.read<CeilingSensorBloc>().add(GetCeilingDeviceReportsEvent(
code: '', deviceUuid: device.uuid!));
context
.read<CeilingSensorBloc>()
.add(GetCeilingDeviceReportsEvent(code: '', deviceUuid: device.uuid!));
},
child: const PresenceStaticWidget(
icon: Assets.helpDescriptionIcon,
@@ -38,14 +38,13 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
on<GarageDoorBatchControlEvent>(_onBatchControl);
on<GarageDoorFetchBatchStatusEvent>(_onFetchBatchStatus);
on<GarageDoorFactoryResetEvent>(_onFactoryReset);
on<EditGarageDoorScheduleEvent>(_onEditSchedule);
}
void _fetchGarageDoorStatus(
GarageDoorInitialEvent event, Emitter<GarageDoorState> emit) async {
void _fetchGarageDoorStatus(GarageDoorInitialEvent event, Emitter<GarageDoorState> emit) async {
emit(GarageDoorLoadingState());
try {
var response =
await DevicesManagementApi().getDeviceStatus(event.deviceId);
var response = await DevicesManagementApi().getDeviceStatus(event.deviceId);
deviceStatus = GarageDoorStatusModel.fromJson(deviceId, response.status);
emit(GarageDoorLoadedState(status: deviceStatus));
} catch (e) {
@@ -53,22 +52,18 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
}
}
Future<void> _onFetchBatchStatus(GarageDoorFetchBatchStatusEvent event,
Emitter<GarageDoorState> emit) async {
Future<void> _onFetchBatchStatus(GarageDoorFetchBatchStatusEvent event, Emitter<GarageDoorState> emit) async {
emit(GarageDoorLoadingState());
try {
final status =
await DevicesManagementApi().getBatchStatus(event.deviceIds);
deviceStatus =
GarageDoorStatusModel.fromJson(event.deviceIds.first, status.status);
final status = await DevicesManagementApi().getBatchStatus(event.deviceIds);
deviceStatus = GarageDoorStatusModel.fromJson(event.deviceIds.first, status.status);
emit(GarageDoorBatchStatusLoaded(deviceStatus));
} catch (e) {
emit(GarageDoorBatchControlError(e.toString()));
}
}
Future<void> _addSchedule(
AddGarageDoorScheduleEvent event, Emitter<GarageDoorState> emit) async {
Future<void> _addSchedule(AddGarageDoorScheduleEvent event, Emitter<GarageDoorState> emit) async {
try {
ScheduleEntry newSchedule = ScheduleEntry(
category: event.category,
@@ -76,11 +71,9 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
function: Status(code: 'switch_1', value: event.functionOn),
days: ScheduleModel.convertSelectedDaysToStrings(event.selectedDays),
);
bool success =
await DevicesManagementApi().addScheduleRecord(newSchedule, deviceId);
bool success = await DevicesManagementApi().addScheduleRecord(newSchedule, deviceId);
if (success) {
add(FetchGarageDoorSchedulesEvent(
deviceId: deviceId, category: 'switch_1'));
add(FetchGarageDoorSchedulesEvent(deviceId: deviceId, category: 'switch_1'));
} else {
emit(GarageDoorLoadedState(status: deviceStatus));
}
@@ -89,19 +82,16 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
}
}
void _onUpdateCountdownAlarm(
UpdateCountdownAlarmEvent event, Emitter<GarageDoorState> emit) {
void _onUpdateCountdownAlarm(UpdateCountdownAlarmEvent event, Emitter<GarageDoorState> emit) {
final currentState = state;
if (currentState is GarageDoorLoadedState) {
emit(currentState.copyWith(
status:
currentState.status.copyWith(countdownAlarm: event.countdownAlarm),
status: currentState.status.copyWith(countdownAlarm: event.countdownAlarm),
));
}
}
void _onUpdateTrTimeCon(
UpdateTrTimeConEvent event, Emitter<GarageDoorState> emit) {
void _onUpdateTrTimeCon(UpdateTrTimeConEvent event, Emitter<GarageDoorState> emit) {
final currentState = state;
if (currentState is GarageDoorLoadedState) {
emit(currentState.copyWith(
@@ -110,8 +100,7 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
}
}
Future<void> _updateSchedule(UpdateGarageDoorScheduleEvent event,
Emitter<GarageDoorState> emit) async {
Future<void> _updateSchedule(UpdateGarageDoorScheduleEvent event, Emitter<GarageDoorState> emit) async {
try {
final updatedSchedules = deviceStatus.schedules?.map((schedule) {
if (schedule.scheduleId == event.scheduleId) {
@@ -138,15 +127,12 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
}
}
Future<void> _deleteSchedule(DeleteGarageDoorScheduleEvent event,
Emitter<GarageDoorState> emit) async {
Future<void> _deleteSchedule(DeleteGarageDoorScheduleEvent event, Emitter<GarageDoorState> emit) async {
try {
bool success = await DevicesManagementApi()
.deleteScheduleRecord(deviceStatus.uuid, event.scheduleId);
bool success = await DevicesManagementApi().deleteScheduleRecord(deviceStatus.uuid, event.scheduleId);
if (success) {
final updatedSchedules = deviceStatus.schedules
?.where((schedule) => schedule.scheduleId != event.scheduleId)
.toList();
final updatedSchedules =
deviceStatus.schedules?.where((schedule) => schedule.scheduleId != event.scheduleId).toList();
deviceStatus = deviceStatus.copyWith(schedules: updatedSchedules);
emit(GarageDoorLoadedState(status: deviceStatus));
} else {
@@ -157,12 +143,11 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
}
}
Future<void> _fetchSchedules(FetchGarageDoorSchedulesEvent event,
Emitter<GarageDoorState> emit) async {
Future<void> _fetchSchedules(FetchGarageDoorSchedulesEvent event, Emitter<GarageDoorState> emit) async {
emit(ScheduleGarageLoadingState());
try {
List<ScheduleModel> schedules = await DevicesManagementApi()
.getDeviceSchedules(deviceStatus.uuid, event.category);
List<ScheduleModel> schedules =
await DevicesManagementApi().getDeviceSchedules(deviceStatus.uuid, event.category);
deviceStatus = deviceStatus.copyWith(schedules: schedules);
emit(
GarageDoorLoadedState(
@@ -180,37 +165,30 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
}
}
Future<void> _updateSelectedTime(
UpdateSelectedTimeEvent event, Emitter<GarageDoorState> emit) async {
Future<void> _updateSelectedTime(UpdateSelectedTimeEvent event, Emitter<GarageDoorState> emit) async {
final currentState = state;
if (currentState is GarageDoorLoadedState) {
emit(currentState.copyWith(selectedTime: event.selectedTime));
}
}
Future<void> _updateSelectedDay(
UpdateSelectedDayEvent event, Emitter<GarageDoorState> emit) async {
Future<void> _updateSelectedDay(UpdateSelectedDayEvent event, Emitter<GarageDoorState> emit) async {
final currentState = state;
if (currentState is GarageDoorLoadedState) {
List<bool> updatedDays = List.from(currentState.selectedDays);
updatedDays[event.dayIndex] = event.isSelected;
emit(currentState.copyWith(
selectedDays: updatedDays, selectedTime: currentState.selectedTime));
emit(currentState.copyWith(selectedDays: updatedDays, selectedTime: currentState.selectedTime));
}
}
Future<void> _updateFunctionOn(
UpdateFunctionOnEvent event, Emitter<GarageDoorState> emit) async {
Future<void> _updateFunctionOn(UpdateFunctionOnEvent event, Emitter<GarageDoorState> emit) async {
final currentState = state;
if (currentState is GarageDoorLoadedState) {
emit(currentState.copyWith(
functionOn: event.functionOn,
selectedTime: currentState.selectedTime));
emit(currentState.copyWith(functionOn: event.functionOn, selectedTime: currentState.selectedTime));
}
}
Future<void> _initializeAddSchedule(
InitializeAddScheduleEvent event, Emitter<GarageDoorState> emit) async {
Future<void> _initializeAddSchedule(InitializeAddScheduleEvent event, Emitter<GarageDoorState> emit) async {
final currentState = state;
if (currentState is GarageDoorLoadedState) {
emit(currentState.copyWith(
@@ -222,25 +200,20 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
}
}
Future<void> _fetchRecords(
FetchGarageDoorRecordsEvent event, Emitter<GarageDoorState> emit) async {
Future<void> _fetchRecords(FetchGarageDoorRecordsEvent event, Emitter<GarageDoorState> emit) async {
emit(GarageDoorReportsLoadingState());
try {
final from = DateTime.now()
.subtract(const Duration(days: 30))
.millisecondsSinceEpoch;
final from = DateTime.now().subtract(const Duration(days: 30)).millisecondsSinceEpoch;
final to = DateTime.now().millisecondsSinceEpoch;
final DeviceReport records =
await DevicesManagementApi.getDeviceReportsByDate(
event.deviceId, 'switch_1', from.toString(), to.toString());
await DevicesManagementApi.getDeviceReportsByDate(event.deviceId, 'switch_1', from.toString(), to.toString());
emit(GarageDoorReportsState(deviceReport: records));
} catch (e) {
emit(GarageDoorReportsFailedState(error: e.toString()));
}
}
Future<void> _onBatchControl(
GarageDoorBatchControlEvent event, Emitter<GarageDoorState> emit) async {
Future<void> _onBatchControl(GarageDoorBatchControlEvent event, Emitter<GarageDoorState> emit) async {
final oldValue = event.code == 'switch_1' ? deviceStatus.switch1 : false;
_updateLocalValue(event.code, event.value);
@@ -260,13 +233,11 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
}
}
void _backToGridView(
BackToGarageDoorGridViewEvent event, Emitter<GarageDoorState> emit) {
void _backToGridView(BackToGarageDoorGridViewEvent event, Emitter<GarageDoorState> emit) {
emit(GarageDoorLoadedState(status: deviceStatus));
}
void _handleUpdate(
GarageDoorUpdatedEvent event, Emitter<GarageDoorState> emit) {
void _handleUpdate(GarageDoorUpdatedEvent event, Emitter<GarageDoorState> emit) {
emit(GarageDoorLoadedState(status: deviceStatus));
}
@@ -282,11 +253,9 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
late bool status;
await Future.delayed(const Duration(milliseconds: 500));
if (isBatch) {
status = await DevicesManagementApi()
.deviceBatchControl(deviceId, code, value);
status = await DevicesManagementApi().deviceBatchControl(deviceId, code, value);
} else {
status = await DevicesManagementApi()
.deviceControl(deviceId, Status(code: code, value: value));
status = await DevicesManagementApi().deviceControl(deviceId, Status(code: code, value: value));
}
if (!status) {
@@ -301,12 +270,10 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
}
}
Future<void> _onFactoryReset(
GarageDoorFactoryResetEvent event, Emitter<GarageDoorState> emit) async {
Future<void> _onFactoryReset(GarageDoorFactoryResetEvent event, Emitter<GarageDoorState> emit) async {
emit(GarageDoorLoadingState());
try {
final response = await DevicesManagementApi()
.factoryReset(event.factoryReset, event.deviceId);
final response = await DevicesManagementApi().factoryReset(event.factoryReset, event.deviceId);
if (!response) {
emit(const GarageDoorErrorState(message: 'Failed to reset device'));
} else {
@@ -317,47 +284,34 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
}
}
void _increaseDelay(
IncreaseGarageDoorDelayEvent event, Emitter<GarageDoorState> emit) async {
void _increaseDelay(IncreaseGarageDoorDelayEvent event, Emitter<GarageDoorState> emit) async {
// if (deviceStatus.countdown1 != 0) {
try {
deviceStatus = deviceStatus.copyWith(
delay: deviceStatus.delay + Duration(minutes: 10));
deviceStatus = deviceStatus.copyWith(delay: deviceStatus.delay + Duration(minutes: 10));
emit(GarageDoorLoadedState(status: deviceStatus));
add(GarageDoorControlEvent(
deviceId: event.deviceId,
value: deviceStatus.delay.inSeconds,
code: 'countdown_1'));
add(GarageDoorControlEvent(deviceId: event.deviceId, value: deviceStatus.delay.inSeconds, code: 'countdown_1'));
} catch (e) {
emit(GarageDoorErrorState(message: e.toString()));
}
// }
}
void _decreaseDelay(
DecreaseGarageDoorDelayEvent event, Emitter<GarageDoorState> emit) async {
void _decreaseDelay(DecreaseGarageDoorDelayEvent event, Emitter<GarageDoorState> emit) async {
// if (deviceStatus.countdown1 != 0) {
try {
if (deviceStatus.delay.inMinutes > 10) {
deviceStatus = deviceStatus.copyWith(
delay: deviceStatus.delay - Duration(minutes: 10));
deviceStatus = deviceStatus.copyWith(delay: deviceStatus.delay - Duration(minutes: 10));
}
emit(GarageDoorLoadedState(status: deviceStatus));
add(GarageDoorControlEvent(
deviceId: event.deviceId,
value: deviceStatus.delay.inSeconds,
code: 'countdown_1'));
add(GarageDoorControlEvent(deviceId: event.deviceId, value: deviceStatus.delay.inSeconds, code: 'countdown_1'));
} catch (e) {
emit(GarageDoorErrorState(message: e.toString()));
}
//}
}
void _garageDoorControlEvent(
GarageDoorControlEvent event, Emitter<GarageDoorState> emit) async {
final oldValue = event.code == 'countdown_1'
? deviceStatus.countdown1
: deviceStatus.switch1;
void _garageDoorControlEvent(GarageDoorControlEvent event, Emitter<GarageDoorState> emit) async {
final oldValue = event.code == 'countdown_1' ? deviceStatus.countdown1 : deviceStatus.switch1;
_updateLocalValue(event.code, event.value);
emit(GarageDoorLoadedState(status: deviceStatus));
final success = await _runDeBouncer(
@@ -373,8 +327,7 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
}
}
void _revertValue(
String code, dynamic oldValue, Emitter<GarageDoorState> emit) {
void _revertValue(String code, dynamic oldValue, Emitter<GarageDoorState> emit) {
switch (code) {
case 'switch_1':
if (oldValue is bool) {
@@ -383,8 +336,7 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
break;
case 'countdown_1':
if (oldValue is int) {
deviceStatus = deviceStatus.copyWith(
countdown1: oldValue, delay: Duration(seconds: oldValue));
deviceStatus = deviceStatus.copyWith(countdown1: oldValue, delay: Duration(seconds: oldValue));
}
break;
// Add other cases if needed
@@ -406,8 +358,7 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
break;
case 'countdown_1':
if (value is int) {
deviceStatus = deviceStatus.copyWith(
countdown1: value, delay: Duration(seconds: value));
deviceStatus = deviceStatus.copyWith(countdown1: value, delay: Duration(seconds: value));
}
break;
case 'countdown_alarm':
@@ -420,6 +371,25 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
deviceStatus = deviceStatus.copyWith(trTimeCon: value);
}
break;
case 'door_state_1':
if (value is String) {
deviceStatus = deviceStatus.copyWith(doorState1: value);
}
break;
case 'door_control_1':
if (value is String) {
deviceStatus = deviceStatus.copyWith(doorControl1: value);
}
break;
case 'voice_control_1':
if (value is bool) {
deviceStatus = deviceStatus.copyWith(voiceControl1: value);
}
break;
case 'door_contact_state':
if (value is bool) {
deviceStatus = deviceStatus.copyWith(doorContactState: value);
}
default:
break;
}
@@ -430,4 +400,24 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
_timer?.cancel();
return super.close();
}
FutureOr<void> _onEditSchedule(EditGarageDoorScheduleEvent event, Emitter<GarageDoorState> emit) async {
try {
ScheduleEntry newSchedule = ScheduleEntry(
scheduleId: event.scheduleId,
category: event.category,
time: formatTimeOfDayToISO(event.time),
function: Status(code: 'switch_1', value: event.functionOn),
days: ScheduleModel.convertSelectedDaysToStrings(event.selectedDays),
);
bool success = await DevicesManagementApi().editScheduleRecord(deviceId, newSchedule);
if (success) {
add(FetchGarageDoorSchedulesEvent(deviceId: deviceId, category: 'switch_1'));
} else {
emit(GarageDoorLoadedState(status: deviceStatus));
}
} catch (e) {
emit(GarageDoorLoadedState(status: deviceStatus));
}
}
}
@@ -25,8 +25,7 @@ class GarageDoorControlEvent extends GarageDoorEvent {
final dynamic value;
final String code;
const GarageDoorControlEvent(
{required this.deviceId, required this.value, required this.code});
const GarageDoorControlEvent({required this.deviceId, required this.value, required this.code});
@override
List<Object?> get props => [deviceId, value];
@@ -46,6 +45,22 @@ class AddGarageDoorScheduleEvent extends GarageDoorEvent {
});
}
class EditGarageDoorScheduleEvent extends GarageDoorEvent {
final String scheduleId;
final String category;
final TimeOfDay time;
final bool functionOn;
final List<bool> selectedDays;
const EditGarageDoorScheduleEvent({
required this.scheduleId,
required this.category,
required this.time,
required this.functionOn,
required this.selectedDays,
});
}
class UpdateGarageDoorScheduleEvent extends GarageDoorEvent {
final String deviceId;
final String scheduleId;
@@ -106,8 +121,7 @@ class FetchGarageDoorRecordsEvent extends GarageDoorEvent {
final String deviceId;
final String code;
const FetchGarageDoorRecordsEvent(
{required this.deviceId, required this.code});
const FetchGarageDoorRecordsEvent({required this.deviceId, required this.code});
@override
List<Object?> get props => [deviceId, code];
@@ -76,35 +76,30 @@ class GarageDoorDialogHelper {
padding: 8,
backgroundColor: ColorsManager.boxColor,
borderRadius: 15,
onPressed: isEdit == true
? null
: () async {
TimeOfDay? time = await showTimePicker(
context: context,
initialTime:
state.selectedTime ?? TimeOfDay.now(),
builder: (context, child) {
return Theme(
data: Theme.of(context).copyWith(
colorScheme: const ColorScheme.light(
primary: ColorsManager.primaryColor,
),
),
child: child!,
);
},
);
if (time != null) {
bloc.add(UpdateSelectedTimeEvent(time));
}
},
onPressed: () async {
TimeOfDay? time = await showTimePicker(
context: context,
initialTime: state.selectedTime ?? TimeOfDay.now(),
builder: (context, child) {
return Theme(
data: Theme.of(context).copyWith(
colorScheme: const ColorScheme.light(
primary: ColorsManager.primaryColor,
),
),
child: child!,
);
},
);
if (time != null) {
bloc.add(UpdateSelectedTimeEvent(time));
}
},
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
state.selectedTime == null
? 'Time'
: state.selectedTime!.format(context),
state.selectedTime == null ? 'Time' : state.selectedTime!.format(context),
style: context.textTheme.bodySmall!.copyWith(
color: ColorsManager.grayColor,
),
@@ -119,8 +114,7 @@ class GarageDoorDialogHelper {
),
),
const SizedBox(height: 16),
_buildDayCheckboxes(context, state.selectedDays,
isEdit: isEdit),
_buildDayCheckboxes(context, state.selectedDays, isEdit: isEdit),
const SizedBox(height: 16),
_buildFunctionSwitch(context, state.functionOn, isEdit),
],
@@ -147,7 +141,13 @@ class GarageDoorDialogHelper {
onPressed: () {
if (state.selectedTime != null) {
if (state.isEditing && index != null) {
return;
bloc.add(EditGarageDoorScheduleEvent(
scheduleId: schedule?.scheduleId ?? '',
category: 'switch_1',
time: state.selectedTime!,
selectedDays: state.selectedDays,
functionOn: state.functionOn,
));
} else {
bloc.add(AddGarageDoorScheduleEvent(
category: 'switch_1',
@@ -199,9 +199,7 @@ class GarageDoorDialogHelper {
return daysBoolean;
}
static Widget _buildDayCheckboxes(
BuildContext context, List<bool> selectedDays,
{bool? isEdit}) {
static Widget _buildDayCheckboxes(BuildContext context, List<bool> selectedDays, {bool? isEdit}) {
final dayLabels = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
return Row(
@@ -210,13 +208,9 @@ class GarageDoorDialogHelper {
children: [
Checkbox(
value: selectedDays[index],
onChanged: isEdit == true
? null
: (bool? value) {
context
.read<GarageDoorBloc>()
.add(UpdateSelectedDayEvent(index, value!));
},
onChanged: (bool? value) {
context.read<GarageDoorBloc>().add(UpdateSelectedDayEvent(index, value!));
},
),
Text(dayLabels[index]),
],
@@ -225,27 +219,19 @@ class GarageDoorDialogHelper {
);
}
static Widget _buildFunctionSwitch(
BuildContext context, bool isOn, bool? isEdit) {
static Widget _buildFunctionSwitch(BuildContext context, bool isOn, bool? isEdit) {
return Row(
children: [
Text(
'Function:',
style: context.textTheme.bodySmall!
.copyWith(color: ColorsManager.grayColor),
style: context.textTheme.bodySmall!.copyWith(color: ColorsManager.grayColor),
),
const SizedBox(width: 10),
Radio<bool>(
value: true,
groupValue: isOn,
onChanged: (bool? value) {
if (isEdit == true) {
return;
} else {
context
.read<GarageDoorBloc>()
.add(const UpdateFunctionOnEvent(functionOn: true));
}
context.read<GarageDoorBloc>().add(const UpdateFunctionOnEvent(functionOn: true));
},
),
const Text('On'),
@@ -254,13 +240,7 @@ class GarageDoorDialogHelper {
value: false,
groupValue: isOn,
onChanged: (bool? value) {
if (isEdit == true) {
return;
} else {
context
.read<GarageDoorBloc>()
.add(const UpdateFunctionOnEvent(functionOn: false));
}
context.read<GarageDoorBloc>().add(const UpdateFunctionOnEvent(functionOn: false));
},
),
const Text('Off'),
@@ -317,33 +297,36 @@ class GarageDoorDialogHelper {
alertBody: TimeOutAlarmDialogBody(bloc),
title: 'Time Out Alarm',
onConfirm: () {
final updatedState =
context.read<GarageDoorBloc>().state;
if (updatedState
is GarageDoorLoadedState) {
final updatedState = context.read<GarageDoorBloc>().state;
if (updatedState is GarageDoorLoadedState) {
context.read<GarageDoorBloc>().add(
GarageDoorControlEvent(
deviceId:
updatedState.status.uuid,
deviceId: updatedState.status.uuid,
code: 'countdown_alarm',
value: updatedState
.status.countdownAlarm,
value: updatedState.status.countdownAlarm,
),
);
Navigator.pop(context);
// context.read<GarageDoorBloc>().add(
// GarageDoorInitialEvent(
// bloc.deviceId));
}
});
},
child: ToggleWidget(
icon: "-1",
value: state.status.countdownAlarm > 0,
code: 'countdown_alarm',
value: state.status.doorState1 == "close_time_alarm" ? false : true,
code: 'door_state_1',
deviceId: bloc.deviceId,
label: 'Alarm when door is open',
onChange: (value) {}),
onChange: (value) {
context.read<GarageDoorBloc>().add(
GarageDoorControlEvent(
deviceId: bloc.deviceId,
code: 'door_state_1',
value: state.status.doorState1 == "close_time_alarm"
? "unclosed_time"
: "close_time_alarm",
),
);
}),
),
),
const SizedBox(
@@ -365,23 +348,16 @@ class GarageDoorDialogHelper {
),
title: 'Opening and Closing Time',
onConfirm: () {
final updatedState =
context.read<GarageDoorBloc>().state;
if (updatedState
is GarageDoorLoadedState) {
final updatedState = context.read<GarageDoorBloc>().state;
if (updatedState is GarageDoorLoadedState) {
context.read<GarageDoorBloc>().add(
GarageDoorControlEvent(
deviceId:
updatedState.status.uuid,
deviceId: updatedState.status.uuid,
code: 'tr_timecon',
value: updatedState
.status.trTimeCon,
value: updatedState.status.trTimeCon,
),
);
Navigator.pop(context);
// context.read<GarageDoorBloc>().add(
// GarageDoorInitialEvent(
// bloc.deviceId));
}
});
},
@@ -65,7 +65,7 @@ class GarageDoorStatusModel {
voiceControl1 = status.value ?? false;
break;
case 'door_state_1':
doorState1 = status.value ?? 'closed';
doorState1 = status.value ?? 'close_time_alarm';
break;
}
}
@@ -26,8 +26,7 @@ class ScheduleGarageTableWidget extends StatelessWidget {
Table(
border: TableBorder.all(
color: ColorsManager.graysColor,
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(20), topRight: Radius.circular(20)),
borderRadius: const BorderRadius.only(topLeft: Radius.circular(20), topRight: Radius.circular(20)),
),
children: [
TableRow(
@@ -51,21 +50,17 @@ class ScheduleGarageTableWidget extends StatelessWidget {
BlocBuilder<GarageDoorBloc, GarageDoorState>(
builder: (context, state) {
if (state is ScheduleGarageLoadingState) {
return const SizedBox(
height: 200,
child: Center(child: CircularProgressIndicator()));
return const SizedBox(height: 200, child: Center(child: CircularProgressIndicator()));
}
if (state is GarageDoorLoadedState &&
state.status.schedules == null) {
if (state is GarageDoorLoadedState && state.status.schedules?.isEmpty == true) {
return _buildEmptyState(context);
} else if (state is GarageDoorLoadedState) {
return Container(
height: 200,
decoration: BoxDecoration(
border: Border.all(color: ColorsManager.graysColor),
borderRadius: const BorderRadius.only(
bottomLeft: Radius.circular(20),
bottomRight: Radius.circular(20)),
borderRadius:
const BorderRadius.only(bottomLeft: Radius.circular(20), bottomRight: Radius.circular(20)),
),
child: _buildTableBody(state, context));
}
@@ -83,8 +78,7 @@ class ScheduleGarageTableWidget extends StatelessWidget {
height: 200,
decoration: BoxDecoration(
border: Border.all(color: ColorsManager.graysColor),
borderRadius: const BorderRadius.only(
bottomLeft: Radius.circular(20), bottomRight: Radius.circular(20)),
borderRadius: const BorderRadius.only(bottomLeft: Radius.circular(20), bottomRight: Radius.circular(20)),
),
child: Center(
child: Column(
@@ -118,8 +112,7 @@ class ScheduleGarageTableWidget extends StatelessWidget {
children: [
if (state.status.schedules != null)
for (int i = 0; i < state.status.schedules!.length; i++)
_buildScheduleRow(
state.status.schedules![i], i, context, state),
_buildScheduleRow(state.status.schedules![i], i, context, state),
],
),
),
@@ -141,8 +134,7 @@ class ScheduleGarageTableWidget extends StatelessWidget {
);
}
TableRow _buildScheduleRow(ScheduleModel schedule, int index,
BuildContext context, GarageDoorLoadedState state) {
TableRow _buildScheduleRow(ScheduleModel schedule, int index, BuildContext context, GarageDoorLoadedState state) {
return TableRow(
children: [
Center(
@@ -160,8 +152,7 @@ class ScheduleGarageTableWidget extends StatelessWidget {
width: 24,
height: 24,
child: schedule.enable
? const Icon(Icons.radio_button_checked,
color: ColorsManager.blueColor)
? const Icon(Icons.radio_button_checked, color: ColorsManager.blueColor)
: const Icon(
Icons.radio_button_unchecked,
color: ColorsManager.grayColor,
@@ -169,9 +160,7 @@ class ScheduleGarageTableWidget extends StatelessWidget {
),
),
),
Center(
child: Text(_getSelectedDays(
ScheduleModel.parseSelectedDays(schedule.days)))),
Center(child: Text(_getSelectedDays(ScheduleModel.parseSelectedDays(schedule.days)))),
Center(child: Text(formatIsoStringToTime(schedule.time, context))),
Center(child: Text(schedule.function.value ? 'On' : 'Off')),
Center(
@@ -181,24 +170,18 @@ class ScheduleGarageTableWidget extends StatelessWidget {
TextButton(
style: TextButton.styleFrom(padding: EdgeInsets.zero),
onPressed: () {
GarageDoorDialogHelper.showAddGarageDoorScheduleDialog(
context,
schedule: schedule,
index: index,
isEdit: true);
GarageDoorDialogHelper.showAddGarageDoorScheduleDialog(context,
schedule: schedule, index: index, isEdit: true);
},
child: Text(
'Edit',
style: context.textTheme.bodySmall!
.copyWith(color: ColorsManager.blueColor),
style: context.textTheme.bodySmall!.copyWith(color: ColorsManager.blueColor),
),
),
TextButton(
style: TextButton.styleFrom(padding: EdgeInsets.zero),
onPressed: () {
context
.read<GarageDoorBloc>()
.add(DeleteGarageDoorScheduleEvent(
context.read<GarageDoorBloc>().add(DeleteGarageDoorScheduleEvent(
index: index,
scheduleId: schedule.scheduleId,
deviceId: state.status.uuid,
@@ -206,8 +189,7 @@ class ScheduleGarageTableWidget extends StatelessWidget {
},
child: Text(
'Delete',
style: context.textTheme.bodySmall!
.copyWith(color: ColorsManager.blueColor),
style: context.textTheme.bodySmall!.copyWith(color: ColorsManager.blueColor),
),
),
],
@@ -16,12 +16,10 @@ class GateWayBloc extends Bloc<GateWayEvent, GateWayState> {
on<GateWayFactoryReset>(_onFactoryReset);
}
FutureOr<void> _getGatWayById(
GatWayById event, Emitter<GateWayState> emit) async {
FutureOr<void> _getGatWayById(GatWayById event, Emitter<GateWayState> emit) async {
emit(GatewayLoadingState());
try {
List<DeviceModel> devicesList =
await DevicesManagementApi.getDevicesByGatewayId(event.getWayId);
List<DeviceModel> devicesList = await DevicesManagementApi.getDevicesByGatewayId(event.getWayId);
emit(UpdateGatewayState(list: devicesList));
} catch (e) {
@@ -30,8 +28,7 @@ class GateWayBloc extends Bloc<GateWayEvent, GateWayState> {
}
}
FutureOr<void> _onFactoryReset(
GateWayFactoryReset event, Emitter<GateWayState> emit) async {
FutureOr<void> _onFactoryReset(GateWayFactoryReset event, Emitter<GateWayState> emit) async {
emit(GatewayLoadingState());
try {
final response = await DevicesManagementApi().factoryReset(
@@ -74,7 +74,7 @@ class _DeviceItem extends StatelessWidget {
padding: const EdgeInsets.all(8),
color: ColorsManager.whiteColors,
child: SvgPicture.asset(
device.icon,
device.icon ?? 'assets/icons/gateway.svg',
width: 35,
height: 35,
fit: BoxFit.contain,
@@ -2,9 +2,18 @@ import 'package:flutter/material.dart';
import 'package:syncrow_web/pages/device_managment/shared/toggle_widget.dart';
import 'package:syncrow_web/utils/color_manager.dart';
class NotificationDialog extends StatelessWidget {
class NotificationDialog extends StatefulWidget {
const NotificationDialog({super.key});
@override
State<NotificationDialog> createState() => _NotificationDialogState();
}
class _NotificationDialogState extends State<NotificationDialog> {
bool isLowBatteryNotificationEnabled = true;
bool isClosingRemindersEnabled = true;
bool isDoorAlarmEnabled = true;
@override
Widget build(BuildContext context) {
return Dialog(
@@ -14,7 +23,7 @@ class NotificationDialog extends StatelessWidget {
borderRadius: BorderRadius.circular(20),
),
child: SizedBox(
width: 798,
width: 660,
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(20.0),
@@ -61,29 +70,53 @@ class NotificationDialog extends StatelessWidget {
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ToggleWidget(
value: true,
code: 'notification',
deviceId: '',
label: 'Low Battery',
onChange: (v) {},
icon: '-1',
SizedBox(
width: 170,
height: 135,
child: ToggleWidget(
value: isLowBatteryNotificationEnabled,
code: 'notification',
deviceId: '',
label: 'Low Battery',
onChange: (v) {
setState(() {
isLowBatteryNotificationEnabled = v;
});
},
icon: '-1',
),
),
ToggleWidget(
value: true,
code: 'notification',
deviceId: '',
label: 'Closing\nReminders',
onChange: (v) {},
icon: '-1',
SizedBox(
width: 170,
height: 135,
child: ToggleWidget(
value: isClosingRemindersEnabled,
code: 'notification',
deviceId: '',
label: 'Closing\nReminders',
onChange: (v) {
setState(() {
isClosingRemindersEnabled = v;
});
},
icon: '-1',
),
),
ToggleWidget(
value: true,
code: 'notification',
deviceId: '',
label: 'Door Alarm',
onChange: (v) {},
icon: '-1',
SizedBox(
width: 170,
height: 135,
child: ToggleWidget(
value: isDoorAlarmEnabled,
code: 'notification',
deviceId: '',
label: 'Door Alarm',
onChange: (v) {
setState(() {
isDoorAlarmEnabled = v;
});
},
icon: '-1',
),
),
],
),
@@ -10,14 +10,12 @@ import 'package:syncrow_web/services/devices_mang_api.dart';
part 'one_gang_glass_switch_event.dart';
part 'one_gang_glass_switch_state.dart';
class OneGangGlassSwitchBloc
extends Bloc<OneGangGlassSwitchEvent, OneGangGlassSwitchState> {
class OneGangGlassSwitchBloc extends Bloc<OneGangGlassSwitchEvent, OneGangGlassSwitchState> {
OneGangGlassStatusModel deviceStatus;
Timer? _timer;
OneGangGlassSwitchBloc({required String deviceId})
: deviceStatus = OneGangGlassStatusModel(
uuid: deviceId, switch1: false, countDown: 0),
: deviceStatus = OneGangGlassStatusModel(uuid: deviceId, switch1: false, countDown: 0),
super(OneGangGlassSwitchInitial()) {
on<OneGangGlassSwitchFetchDeviceEvent>(_onFetchDeviceStatus);
on<OneGangGlassSwitchControl>(_onControl);
@@ -26,22 +24,19 @@ class OneGangGlassSwitchBloc
on<OneGangGlassFactoryResetEvent>(_onFactoryReset);
}
Future<void> _onFetchDeviceStatus(OneGangGlassSwitchFetchDeviceEvent event,
Emitter<OneGangGlassSwitchState> emit) async {
Future<void> _onFetchDeviceStatus(
OneGangGlassSwitchFetchDeviceEvent event, Emitter<OneGangGlassSwitchState> emit) async {
emit(OneGangGlassSwitchLoading());
try {
final status =
await DevicesManagementApi().getDeviceStatus(event.deviceId);
deviceStatus =
OneGangGlassStatusModel.fromJson(event.deviceId, status.status);
final status = await DevicesManagementApi().getDeviceStatus(event.deviceId);
deviceStatus = OneGangGlassStatusModel.fromJson(event.deviceId, status.status);
emit(OneGangGlassSwitchStatusLoaded(deviceStatus));
} catch (e) {
emit(OneGangGlassSwitchError(e.toString()));
}
}
Future<void> _onControl(OneGangGlassSwitchControl event,
Emitter<OneGangGlassSwitchState> emit) async {
Future<void> _onControl(OneGangGlassSwitchControl event, Emitter<OneGangGlassSwitchState> emit) async {
final oldValue = _getValueByCode(event.code);
_updateLocalValue(event.code, event.value);
@@ -57,12 +52,10 @@ class OneGangGlassSwitchBloc
);
}
Future<void> _onFactoryReset(OneGangGlassFactoryResetEvent event,
Emitter<OneGangGlassSwitchState> emit) async {
Future<void> _onFactoryReset(OneGangGlassFactoryResetEvent event, Emitter<OneGangGlassSwitchState> emit) async {
emit(OneGangGlassSwitchLoading());
try {
final response = await DevicesManagementApi()
.factoryReset(event.factoryReset, event.deviceId);
final response = await DevicesManagementApi().factoryReset(event.factoryReset, event.deviceId);
if (!response) {
emit(OneGangGlassSwitchError('Failed to reset device'));
} else {
@@ -73,12 +66,11 @@ class OneGangGlassSwitchBloc
}
}
Future<void> _onBatchControl(OneGangGlassSwitchBatchControl event,
Emitter<OneGangGlassSwitchState> emit) async {
Future<void> _onBatchControl(OneGangGlassSwitchBatchControl event, Emitter<OneGangGlassSwitchState> emit) async {
final oldValue = _getValueByCode(event.code);
_updateLocalValue(event.code, event.value);
emit(OneGangGlassSwitchBatchStatusLoaded(deviceStatus));
emit(OneGangGlassSwitchStatusLoaded(deviceStatus));
await _runDebounce(
deviceId: event.deviceIds,
@@ -91,15 +83,12 @@ class OneGangGlassSwitchBloc
}
Future<void> _onFetchBatchStatus(
OneGangGlassSwitchFetchBatchStatusEvent event,
Emitter<OneGangGlassSwitchState> emit) async {
OneGangGlassSwitchFetchBatchStatusEvent event, Emitter<OneGangGlassSwitchState> emit) async {
emit(OneGangGlassSwitchLoading());
try {
final status =
await DevicesManagementApi().getBatchStatus(event.deviceIds);
deviceStatus = OneGangGlassStatusModel.fromJson(
event.deviceIds.first, status.status);
emit(OneGangGlassSwitchBatchStatusLoaded(deviceStatus));
final status = await DevicesManagementApi().getBatchStatus(event.deviceIds);
deviceStatus = OneGangGlassStatusModel.fromJson(event.deviceIds.first, status.status);
emit(OneGangGlassSwitchStatusLoaded(deviceStatus));
} catch (e) {
emit(OneGangGlassSwitchError(e.toString()));
}
@@ -128,11 +117,9 @@ class OneGangGlassSwitchBloc
try {
late bool response;
if (isBatch) {
response = await DevicesManagementApi()
.deviceBatchControl(deviceId, code, value);
response = await DevicesManagementApi().deviceBatchControl(deviceId, code, value);
} else {
response = await DevicesManagementApi()
.deviceControl(deviceId, Status(code: code, value: value));
response = await DevicesManagementApi().deviceControl(deviceId, Status(code: code, value: value));
}
if (!response) {
@@ -144,8 +131,7 @@ class OneGangGlassSwitchBloc
});
}
void _revertValueAndEmit(String deviceId, String code, bool oldValue,
Emitter<OneGangGlassSwitchState> emit) {
void _revertValueAndEmit(String deviceId, String code, bool oldValue, Emitter<OneGangGlassSwitchState> emit) {
_updateLocalValue(code, oldValue);
emit(OneGangGlassSwitchStatusLoaded(deviceStatus));
}
@@ -55,7 +55,7 @@ class OneGangGlassSwitchControlView extends StatelessWidget with HelperResponsiv
value: status.switch1,
code: 'switch_1',
deviceId: deviceId,
label: 'Wall Lightً',
label: "Wall Light",
onChange: (value) {
context.read<OneGangGlassSwitchBloc>().add(
OneGangGlassSwitchControl(
@@ -7,8 +7,7 @@ import 'package:syncrow_web/utils/constants/assets.dart';
import 'package:syncrow_web/utils/extension/build_context_x.dart';
class FirmwareUpdateWidget extends StatefulWidget {
const FirmwareUpdateWidget(
{super.key, required this.deviceId, required this.version});
const FirmwareUpdateWidget({super.key, required this.deviceId, required this.version});
final String deviceId;
final int version;
@@ -34,20 +33,23 @@ class _FirmwareUpdateWidgetState extends State<FirmwareUpdateWidget> {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Firmware Update',
style: context.textTheme.titleMedium!.copyWith(
fontWeight: FontWeight.bold,
color: ColorsManager.blackColor,
),
Column(
children: [
Text(
'Firmware Update',
style: context.textTheme.titleMedium!.copyWith(
fontWeight: FontWeight.bold,
color: ColorsManager.blackColor,
),
),
Text(
'Are you sure?',
style: context.textTheme.bodySmall!.copyWith(
color: ColorsManager.grayColor,
),
),
],
),
Text(
'Are you sure?',
style: context.textTheme.bodySmall!.copyWith(
color: ColorsManager.grayColor,
),
),
const SizedBox(height: 16),
Row(
children: [
Flexible(
@@ -7,8 +7,7 @@ import 'package:syncrow_web/pages/device_managment/all_devices/helper/route_cont
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
import 'package:syncrow_web/utils/color_manager.dart';
class DeviceBatchControlDialog extends StatelessWidget
with RouteControlsBasedCode {
class DeviceBatchControlDialog extends StatelessWidget with RouteControlsBasedCode {
final List<AllDevicesModel> devices;
const DeviceBatchControlDialog({super.key, required this.devices});
@@ -110,11 +109,11 @@ String getBatchDialogName(AllDevicesModel device) {
case '1G':
return "Smart Light Switch";
case '2G':
return "2Gang Light";
return "Smart Light Switch";
case '3G':
return "Living Room";
return "Smart Light Switch";
case 'GW':
return "GateWay";
return "Gateway";
case 'DL':
return "Door Lock";
case 'WPS':
@@ -124,9 +123,21 @@ String getBatchDialogName(AllDevicesModel device) {
case 'CUR':
return "Smart Curtains";
case 'WH':
return "Smart Water Hater";
return "Smart Water Heater";
case 'AC':
return "Smart AC";
case 'DS':
return "Door / Window Sensor";
case '1GT':
return "Touch Switch";
case '2GT':
return "Touch Switch";
case '3GT':
return "Touch Switch";
case 'GD':
return "Garage Door Opener";
case 'WL':
return "Water Leak Sensor";
default:
return device.categoryName ?? 'Device Control';
}
@@ -31,7 +31,7 @@ class DeviceControlDialog extends StatelessWidget with RouteControlsBasedCode {
children: [
const SizedBox(),
Text(
device.categoryName ?? 'Device Control',
device.productName ?? 'Device Control',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 22,
@@ -2,8 +2,9 @@ import 'package:flutter/material.dart';
import 'package:syncrow_web/utils/color_manager.dart';
class DeviceControlsContainer extends StatelessWidget {
const DeviceControlsContainer({required this.child, super.key});
const DeviceControlsContainer({required this.child, this.padding, super.key});
final Widget child;
final double? padding;
@override
Widget build(BuildContext context) {
@@ -11,9 +12,16 @@ class DeviceControlsContainer extends StatelessWidget {
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: ColorsManager.greyColor.withOpacity(0.2),
border: Border.all(color: ColorsManager.boxDivider),
// boxShadow: <BoxShadow>[
// BoxShadow(
// color: ColorsManager.blackColor.withOpacity(0.05),
// blurRadius: 6.0,
// offset: const Offset(0, 5),
// spreadRadius: 0)
// ],
),
padding: const EdgeInsets.all(12),
padding: EdgeInsets.all(padding ?? 12),
child: child,
);
}
@@ -3,6 +3,8 @@ import 'package:intl/intl.dart';
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_reports.dart';
import 'package:syncrow_web/pages/device_managment/shared/table/table_cell_widget.dart';
import 'package:syncrow_web/pages/device_managment/shared/table/table_header.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/extension/build_context_x.dart';
// ignore: must_be_immutable
class ReportsTable extends StatelessWidget {
@@ -31,81 +33,90 @@ class ReportsTable extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Stack(
children: [
Padding(
padding: const EdgeInsets.all(20.0),
child: Table(
border: TableBorder.all(color: Colors.grey.shade300, width: 1),
columnWidths: const {
0: FlexColumnWidth(),
1: FlexColumnWidth(),
2: FlexColumnWidth(),
},
children: [
TableRow(
decoration: BoxDecoration(color: Colors.grey.shade200),
children: [
const TableHeader(title: 'Date'),
const TableHeader(title: 'Time'),
TableHeader(title: thirdColumnTitle ?? 'Status'),
],
),
if (report.data != null)
...report.data!.asMap().entries.map((entry) {
int index = entry.key;
DeviceEvent data = entry.value;
// Parse eventTime into Date and Time
DateTime eventDateTime =
DateTime.fromMillisecondsSinceEpoch(data.eventTime!);
String date = DateFormat('dd/MM/yyyy').format(eventDateTime);
String time = DateFormat('HH:mm').format(eventDateTime);
String value;
if (hideValueShowDescription == true) {
if (mainDoorSensor != null && mainDoorSensor == true) {
value = data.value == 'true' ? 'Open' : 'Close';
} else if (garageDoorSensor != null &&
garageDoorSensor == true) {
value = data.value == 'true' ? 'Opened' : 'Closed';
} else if (waterLeak != null && waterLeak == true) {
value =
data.value == 'normal' ? 'Normal' : 'Leak Detected';
} else {
value = '${data.value!} ${thirdColumnDescription ?? ''}';
}
} else {
value = '${data.value!} ${thirdColumnDescription ?? ''}';
}
return TableRow(
children: [
TableCellWidget(value: date),
TableCellWidget(value: time),
TableCellWidget(
value: value,
onTap: () => onRowTap(index),
),
],
);
}),
],
),
),
Positioned(
top: 0,
right: 0,
child: IconButton(
icon: const Icon(
Icons.close,
color: Colors.red,
size: 18,
return report.data == null || report.data!.isEmpty
? Container(
padding: const EdgeInsets.all(20.0),
width: MediaQuery.sizeOf(context).width,
alignment: AlignmentDirectional.center,
height: 100,
child: Text(
'No reports found',
style: context.textTheme.bodyLarge!.copyWith(color: ColorsManager.grayColor),
),
onPressed: onClose,
),
),
],
);
)
: Stack(
children: [
Padding(
padding: const EdgeInsets.all(20.0),
child: Table(
border: TableBorder.all(color: Colors.grey.shade300, width: 1),
columnWidths: const {
0: FlexColumnWidth(),
1: FlexColumnWidth(),
2: FlexColumnWidth(),
},
children: [
TableRow(
decoration: BoxDecoration(color: Colors.grey.shade200),
children: [
const TableHeader(title: 'Date'),
const TableHeader(title: 'Time'),
TableHeader(title: thirdColumnTitle ?? 'Status'),
],
),
if (report.data != null)
...report.data!.asMap().entries.map((entry) {
int index = entry.key;
DeviceEvent data = entry.value;
// Parse eventTime into Date and Time
DateTime eventDateTime =
DateTime.fromMillisecondsSinceEpoch(data.eventTime!);
String date = DateFormat('dd/MM/yyyy').format(eventDateTime);
String time = DateFormat('HH:mm').format(eventDateTime);
String value;
if (hideValueShowDescription == true) {
if (mainDoorSensor != null && mainDoorSensor == true) {
value = data.value == 'true' ? 'Open' : 'Close';
} else if (garageDoorSensor != null && garageDoorSensor == true) {
value = data.value == 'true' ? 'Opened' : 'Closed';
} else if (waterLeak != null && waterLeak == true) {
value = data.value == 'normal' ? 'Normal' : 'Leak Detected';
} else {
value = '${data.value!} ${thirdColumnDescription ?? ''}';
}
} else {
value = '${data.value!} ${thirdColumnDescription ?? ''}';
}
return TableRow(
children: [
TableCellWidget(value: date),
TableCellWidget(value: time),
TableCellWidget(
value: value,
onTap: () => onRowTap(index),
),
],
);
})
],
),
),
Positioned(
top: 0,
right: 0,
child: IconButton(
icon: const Icon(
Icons.close,
color: Colors.red,
size: 18,
),
onPressed: onClose,
),
),
],
);
}
}
@@ -1,5 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter_svg/flutter_svg.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/constants/assets.dart';
import 'package:syncrow_web/utils/extension/build_context_x.dart';
@@ -30,13 +31,7 @@ class ToggleWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: ColorsManager.greyColor.withOpacity(0.2),
border: Border.all(color: ColorsManager.boxDivider),
),
padding: const EdgeInsets.all(16),
return DeviceControlsContainer(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
@@ -57,7 +57,7 @@ class ThreeGangGlassSwitchBatchControlView extends StatelessWidget with HelperRe
value: status.switch1,
code: 'switch_1',
deviceId: deviceIds.first,
label: 'Glass Switch 1',
label: "Wall Light",
onChange: (value) {
context.read<ThreeGangGlassSwitchBloc>().add(
ThreeGangGlassSwitchBatchControl(
@@ -72,7 +72,7 @@ class ThreeGangGlassSwitchBatchControlView extends StatelessWidget with HelperRe
value: status.switch2,
code: 'switch_2',
deviceId: deviceIds.first,
label: 'Glass Switch 2',
label: "Ceiling Light",
onChange: (value) {
context.read<ThreeGangGlassSwitchBloc>().add(
ThreeGangGlassSwitchBatchControl(
@@ -87,7 +87,7 @@ class ThreeGangGlassSwitchBatchControlView extends StatelessWidget with HelperRe
value: status.switch3,
code: 'switch_3',
deviceId: deviceIds.first,
label: 'Glass Switch 3',
label: "SpotLight",
onChange: (value) {
context.read<ThreeGangGlassSwitchBloc>().add(
ThreeGangGlassSwitchBatchControl(
@@ -56,7 +56,7 @@ class ThreeGangGlassSwitchControlView extends StatelessWidget with HelperRespons
value: status.switch1,
code: 'switch_1',
deviceId: deviceId,
label: 'Wall Light',
label: "Wall Light",
onChange: (value) {
context.read<ThreeGangGlassSwitchBloc>().add(
ThreeGangGlassSwitchControl(
@@ -71,7 +71,7 @@ class ThreeGangGlassSwitchControlView extends StatelessWidget with HelperRespons
value: status.switch2,
code: 'switch_2',
deviceId: deviceId,
label: 'Ceiling Light',
label: "Ceiling Light",
onChange: (value) {
context.read<ThreeGangGlassSwitchBloc>().add(
ThreeGangGlassSwitchControl(
@@ -86,7 +86,7 @@ class ThreeGangGlassSwitchControlView extends StatelessWidget with HelperRespons
value: status.switch3,
code: 'switch_3',
deviceId: deviceId,
label: 'SpotLight',
label: "SpotLight",
onChange: (value) {
context.read<ThreeGangGlassSwitchBloc>().add(
ThreeGangGlassSwitchControl(
@@ -1,8 +1,8 @@
import 'dart:async';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/event.dart';
import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/state.dart';
import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/wall_event.dart';
import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/wall_state.dart';
import 'package:syncrow_web/pages/device_managment/wall_sensor/model/wall_sensor_model.dart';
import 'package:syncrow_web/services/devices_mang_api.dart';
@@ -38,12 +38,10 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
// Fetch batch status
FutureOr<void> _fetchWallSensorBatchControl(
WallSensorFetchBatchStatusEvent event,
Emitter<WallSensorState> emit) async {
WallSensorFetchBatchStatusEvent event, Emitter<WallSensorState> emit) async {
emit(WallSensorLoadingInitialState());
try {
var response =
await DevicesManagementApi().getBatchStatus(event.devicesIds);
var response = await DevicesManagementApi().getBatchStatus(event.devicesIds);
deviceStatus = WallSensorModel.fromJson(response.status);
emit(WallSensorUpdateState(wallSensorModel: deviceStatus));
} catch (e) {
@@ -70,8 +68,7 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
// } catch (_) {}
// }
void _changeValue(
WallSensorChangeValueEvent event, Emitter<WallSensorState> emit) async {
void _changeValue(WallSensorChangeValueEvent event, Emitter<WallSensorState> emit) async {
emit(WallSensorLoadingNewSate(wallSensorModel: deviceStatus));
if (event.code == 'far_detection') {
deviceStatus.farDetection = event.value;
@@ -128,8 +125,7 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
try {
late bool response;
if (isBatch) {
response = await DevicesManagementApi()
.deviceBatchControl(deviceId, code, value);
response = await DevicesManagementApi().deviceBatchControl(deviceId, code, value);
} else {
response = await DevicesManagementApi()
.deviceControl(deviceId, Status(code: code, value: value));
@@ -148,10 +144,13 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
FutureOr<void> _getDeviceReports(
GetDeviceReportsEvent event, Emitter<WallSensorState> emit) async {
emit(DeviceReportsLoadingState());
// final from = DateTime.now().subtract(const Duration(days: 30)).millisecondsSinceEpoch;
// final to = DateTime.now().millisecondsSinceEpoch;
try {
await DevicesManagementApi.getDeviceReports(deviceId, event.code)
.then((value) {
// await DevicesManagementApi.getDeviceReportsByDate(
// deviceId, event.code, from.toString(), to.toString())
await DevicesManagementApi.getDeviceReports(deviceId, event.code).then((value) {
emit(DeviceReportsState(deviceReport: value, code: event.code));
});
} catch (e) {
@@ -160,13 +159,11 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
}
}
void _showDescription(
ShowDescriptionEvent event, Emitter<WallSensorState> emit) {
void _showDescription(ShowDescriptionEvent event, Emitter<WallSensorState> emit) {
emit(WallSensorShowDescriptionState(description: event.description));
}
void _backToGridView(
BackToGridViewEvent event, Emitter<WallSensorState> emit) {
void _backToGridView(BackToGridViewEvent event, Emitter<WallSensorState> emit) {
emit(WallSensorUpdateState(wallSensorModel: deviceStatus));
}
@@ -4,14 +4,13 @@ import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_re
import 'package:syncrow_web/pages/device_managment/shared/batch_control/factory_reset.dart';
import 'package:syncrow_web/pages/device_managment/shared/batch_control/firmware_update.dart';
import 'package:syncrow_web/pages/device_managment/shared/sensors_widgets/presence_update_data.dart';
import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/bloc.dart';
import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/event.dart';
import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/state.dart';
import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/wall_bloc.dart';
import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/wall_event.dart';
import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/wall_state.dart';
import 'package:syncrow_web/pages/device_managment/wall_sensor/model/wall_sensor_model.dart';
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
class WallSensorBatchControlView extends StatelessWidget
with HelperResponsiveLayout {
class WallSensorBatchControlView extends StatelessWidget with HelperResponsiveLayout {
const WallSensorBatchControlView({super.key, required this.devicesIds});
final List<String> devicesIds;
@@ -26,16 +25,13 @@ class WallSensorBatchControlView extends StatelessWidget
..add(WallSensorFetchBatchStatusEvent(devicesIds)),
child: BlocBuilder<WallSensorBloc, WallSensorState>(
builder: (context, state) {
if (state is WallSensorLoadingInitialState ||
state is DeviceReportsLoadingState) {
if (state is WallSensorLoadingInitialState || state is DeviceReportsLoadingState) {
return const Center(child: CircularProgressIndicator());
} else if (state is WallSensorUpdateState) {
return _buildGridView(context, state.wallSensorModel, isExtraLarge,
isLarge, isMedium);
return _buildGridView(context, state.wallSensorModel, isExtraLarge, isLarge, isMedium);
} else if (state is DeviceReportsFailedState) {
final model = context.read<WallSensorBloc>().deviceStatus;
return _buildGridView(
context, model, isExtraLarge, isLarge, isMedium);
return _buildGridView(context, model, isExtraLarge, isLarge, isMedium);
}
return const Center(child: Text('Error fetching status'));
},
@@ -43,8 +39,8 @@ class WallSensorBatchControlView extends StatelessWidget
);
}
Widget _buildGridView(BuildContext context, WallSensorModel model,
bool isExtraLarge, bool isLarge, bool isMedium) {
Widget _buildGridView(
BuildContext context, WallSensorModel model, bool isExtraLarge, bool isLarge, bool isMedium) {
return GridView(
padding: const EdgeInsets.symmetric(horizontal: 50, vertical: 20),
shrinkWrap: true,
@@ -97,12 +93,11 @@ class WallSensorBatchControlView extends StatelessWidget
maxValue: 10000,
steps: 1,
description: 'sec',
action: (int value) =>
context.read<WallSensorBloc>().add(WallSensorBatchControlEvent(
deviceIds: devicesIds,
code: 'no_one_time',
value: value,
))),
action: (int value) => context.read<WallSensorBloc>().add(WallSensorBatchControlEvent(
deviceIds: devicesIds,
code: 'no_one_time',
value: value,
))),
PresenceUpdateData(
value: model.farDetection.toDouble(),
title: 'Far Detection:',
@@ -3,9 +3,9 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
import 'package:syncrow_web/pages/device_managment/shared/table/description_view.dart';
import 'package:syncrow_web/pages/device_managment/shared/table/report_table.dart';
import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/bloc.dart';
import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/event.dart';
import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/state.dart';
import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/wall_bloc.dart';
import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/wall_event.dart';
import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/wall_state.dart';
import 'package:syncrow_web/pages/device_managment/shared/sensors_widgets/presence_display_data.dart';
import 'package:syncrow_web/pages/device_managment/shared/sensors_widgets/presence_static_widget.dart';
import 'package:syncrow_web/pages/device_managment/shared/sensors_widgets/presence_status.dart';
@@ -14,8 +14,7 @@ import 'package:syncrow_web/pages/device_managment/wall_sensor/model/wall_sensor
import 'package:syncrow_web/utils/constants/assets.dart';
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
class WallSensorControlsView extends StatelessWidget
with HelperResponsiveLayout {
class WallSensorControlsView extends StatelessWidget with HelperResponsiveLayout {
const WallSensorControlsView({super.key, required this.device});
final AllDevicesModel device;
@@ -26,23 +25,19 @@ class WallSensorControlsView extends StatelessWidget
final isLarge = isLargeScreenSize(context);
final isMedium = isMediumScreenSize(context);
return BlocProvider(
create: (context) => WallSensorBloc(deviceId: device.uuid!)
..add(WallSensorFetchStatusEvent()),
create: (context) =>
WallSensorBloc(deviceId: device.uuid!)..add(WallSensorFetchStatusEvent()),
child: BlocBuilder<WallSensorBloc, WallSensorState>(
builder: (context, state) {
if (state is WallSensorLoadingInitialState ||
state is DeviceReportsLoadingState) {
if (state is WallSensorLoadingInitialState || state is DeviceReportsLoadingState) {
return const Center(child: CircularProgressIndicator());
} else if (state is WallSensorUpdateState) {
return _buildGridView(context, state.wallSensorModel, isExtraLarge,
isLarge, isMedium);
return _buildGridView(context, state.wallSensorModel, isExtraLarge, isLarge, isMedium);
} else if (state is DeviceReportsState) {
return ReportsTable(
report: state.deviceReport,
thirdColumnTitle:
state.code == 'illuminance_value' ? "Value" : 'Status',
thirdColumnDescription:
state.code == 'illuminance_value' ? "Lux" : null,
thirdColumnTitle: state.code == 'illuminance_value' ? "Value" : 'Status',
thirdColumnDescription: state.code == 'illuminance_value' ? "Lux" : null,
onRowTap: (index) {},
onClose: () {
context.read<WallSensorBloc>().add(BackToGridViewEvent());
@@ -57,8 +52,7 @@ class WallSensorControlsView extends StatelessWidget
);
} else if (state is DeviceReportsFailedState) {
final model = context.read<WallSensorBloc>().deviceStatus;
return _buildGridView(
context, model, isExtraLarge, isLarge, isMedium);
return _buildGridView(context, model, isExtraLarge, isLarge, isMedium);
}
return const Center(child: Text('Error fetching status'));
},
@@ -66,8 +60,8 @@ class WallSensorControlsView extends StatelessWidget
);
}
Widget _buildGridView(BuildContext context, WallSensorModel model,
bool isExtraLarge, bool isLarge, bool isMedium) {
Widget _buildGridView(
BuildContext context, WallSensorModel model, bool isExtraLarge, bool isLarge, bool isMedium) {
return GridView(
padding: const EdgeInsets.symmetric(horizontal: 50),
shrinkWrap: true,
@@ -136,11 +130,10 @@ class WallSensorControlsView extends StatelessWidget
maxValue: 10000,
steps: 1,
description: 'sec',
action: (int value) =>
context.read<WallSensorBloc>().add(WallSensorChangeValueEvent(
code: 'no_one_time',
value: value,
))),
action: (int value) => context.read<WallSensorBloc>().add(WallSensorChangeValueEvent(
code: 'no_one_time',
value: value,
))),
PresenceUpdateData(
value: model.farDetection.toDouble(),
title: 'Far Detection:',
@@ -157,8 +150,9 @@ class WallSensorControlsView extends StatelessWidget
),
GestureDetector(
onTap: () {
context.read<WallSensorBloc>().add(GetDeviceReportsEvent(
code: 'illuminance_value', deviceUuid: device.uuid!));
context
.read<WallSensorBloc>()
.add(GetDeviceReportsEvent(code: 'illuminance_value', deviceUuid: device.uuid!));
},
child: const PresenceStaticWidget(
icon: Assets.illuminanceRecordIcon,
@@ -167,8 +161,9 @@ class WallSensorControlsView extends StatelessWidget
),
GestureDetector(
onTap: () {
context.read<WallSensorBloc>().add(GetDeviceReportsEvent(
code: 'presence_state', deviceUuid: device.uuid!));
context
.read<WallSensorBloc>()
.add(GetDeviceReportsEvent(code: 'presence_state', deviceUuid: device.uuid!));
},
child: const PresenceStaticWidget(
icon: Assets.presenceRecordIcon,
@@ -1,6 +1,7 @@
// water_heater_bloc.dart
import 'dart:async';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
@@ -30,6 +31,7 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
on<GetSchedulesEvent>(_getSchedule);
on<AddScheduleEvent>(_onAddSchedule);
on<EditWaterHeaterScheduleEvent>(_onEditSchedule);
on<DeleteScheduleEvent>(_onDeleteSchedule);
on<UpdateScheduleEntryEvent>(_onUpdateSchedule);
}
@@ -76,8 +78,7 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
final currentState = state as WaterHeaterDeviceStatusLoaded;
final updatedDays = List<bool>.from(currentState.selectedDays);
updatedDays[event.index] = event.value;
emit(currentState.copyWith(
selectedDays: updatedDays, selectedTime: currentState.selectedTime));
emit(currentState.copyWith(selectedDays: updatedDays, selectedTime: currentState.selectedTime));
}
FutureOr<void> _updateFunctionOn(
@@ -85,8 +86,7 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
Emitter<WaterHeaterState> emit,
) {
final currentState = state as WaterHeaterDeviceStatusLoaded;
emit(currentState.copyWith(
functionOn: event.isOn, selectedTime: currentState.selectedTime));
emit(currentState.copyWith(functionOn: event.isOn, selectedTime: currentState.selectedTime));
}
FutureOr<void> _updateScheduleEvent(
@@ -101,8 +101,7 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
));
}
if (event.scheduleMode == ScheduleModes.countdown) {
final countdownRemaining =
Duration(hours: event.hours, minutes: event.minutes);
final countdownRemaining = Duration(hours: event.hours, minutes: event.minutes);
emit(currentState.copyWith(
scheduleMode: ScheduleModes.countdown,
@@ -112,13 +111,11 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
countdownRemaining: countdownRemaining,
));
if (!currentState.isCountdownActive! &&
countdownRemaining > Duration.zero) {
if (!currentState.isCountdownActive! && countdownRemaining > Duration.zero) {
_startCountdownTimer(emit, countdownRemaining);
}
} else if (event.scheduleMode == ScheduleModes.inching) {
final inchingDuration =
Duration(hours: event.hours, minutes: event.minutes);
final inchingDuration = Duration(hours: event.hours, minutes: event.minutes);
emit(currentState.copyWith(
scheduleMode: ScheduleModes.inching,
@@ -220,8 +217,7 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
try {
final status = await DevicesManagementApi().deviceControl(
event.deviceId,
Status(
code: isCountDown ? 'countdown_1' : 'switch_inching', value: 0),
Status(code: isCountDown ? 'countdown_1' : 'switch_inching', value: 0),
);
if (!status) {
emit(const WaterHeaterFailedState(error: 'Failed to stop schedule.'));
@@ -239,10 +235,8 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
emit(WaterHeaterLoadingState());
try {
final status =
await DevicesManagementApi().getDeviceStatus(event.deviceId);
deviceStatus =
WaterHeaterStatusModel.fromJson(event.deviceId, status.status);
final status = await DevicesManagementApi().getDeviceStatus(event.deviceId);
deviceStatus = WaterHeaterStatusModel.fromJson(event.deviceId, status.status);
if (deviceStatus.scheduleMode == ScheduleModes.countdown) {
final countdownRemaining = Duration(
@@ -340,10 +334,8 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
if (state is WaterHeaterDeviceStatusLoaded) {
final currentState = state as WaterHeaterDeviceStatusLoaded;
if (currentState.countdownRemaining != null &&
currentState.countdownRemaining! > Duration.zero) {
final newRemaining =
currentState.countdownRemaining! - const Duration(minutes: 1);
if (currentState.countdownRemaining != null && currentState.countdownRemaining! > Duration.zero) {
final newRemaining = currentState.countdownRemaining! - const Duration(minutes: 1);
if (newRemaining <= Duration.zero) {
_countdownTimer?.cancel();
@@ -438,8 +430,7 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
}
}
void _revertValue(String code, dynamic oldValue,
void Function(WaterHeaterState state) emit) {
void _revertValue(String code, dynamic oldValue, void Function(WaterHeaterState state) emit) {
_updateLocalValue(code, oldValue);
if (state is WaterHeaterDeviceStatusLoaded) {
final currentState = state as WaterHeaterDeviceStatusLoaded;
@@ -486,13 +477,12 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
return super.close();
}
FutureOr<void> _getSchedule(
GetSchedulesEvent event, Emitter<WaterHeaterState> emit) async {
FutureOr<void> _getSchedule(GetSchedulesEvent event, Emitter<WaterHeaterState> emit) async {
emit(ScheduleLoadingState());
try {
List<ScheduleModel> schedules = await DevicesManagementApi()
.getDeviceSchedules(deviceStatus.uuid, event.category);
List<ScheduleModel> schedules =
await DevicesManagementApi().getDeviceSchedules(deviceStatus.uuid, event.category);
emit(WaterHeaterDeviceStatusLoaded(
deviceStatus,
@@ -524,8 +514,35 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
// emit(ScheduleLoadingState());
bool success = await DevicesManagementApi()
.addScheduleRecord(newSchedule, currentState.status.uuid);
bool success = await DevicesManagementApi().addScheduleRecord(newSchedule, currentState.status.uuid);
if (success) {
add(GetSchedulesEvent(category: 'switch_1', uuid: deviceStatus.uuid));
} else {
emit(currentState);
//emit(const WaterHeaterFailedState(error: 'Failed to add schedule.'));
}
}
}
FutureOr<void> _onEditSchedule(EditWaterHeaterScheduleEvent event, Emitter<WaterHeaterState> emit) async {
if (state is WaterHeaterDeviceStatusLoaded) {
final currentState = state as WaterHeaterDeviceStatusLoaded;
ScheduleEntry newSchedule = ScheduleEntry(
scheduleId: event.scheduleId,
category: event.category,
time: formatTimeOfDayToISO(event.time),
function: Status(code: 'switch_1', value: event.functionOn),
days: ScheduleModel.convertSelectedDaysToStrings(event.selectedDays),
);
// emit(ScheduleLoadingState());
bool success = await DevicesManagementApi().editScheduleRecord(
currentState.status.uuid,
newSchedule,
);
if (success) {
add(GetSchedulesEvent(category: 'switch_1', uuid: deviceStatus.uuid));
@@ -577,13 +594,11 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
// emit(ScheduleLoadingState());
bool success = await DevicesManagementApi()
.deleteScheduleRecord(currentState.status.uuid, event.scheduleId);
bool success = await DevicesManagementApi().deleteScheduleRecord(currentState.status.uuid, event.scheduleId);
if (success) {
final updatedSchedules = currentState.schedules
.where((schedule) => schedule.scheduleId != event.scheduleId)
.toList();
final updatedSchedules =
currentState.schedules.where((schedule) => schedule.scheduleId != event.scheduleId).toList();
emit(currentState.copyWith(schedules: updatedSchedules));
} else {
@@ -593,15 +608,12 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
}
}
FutureOr<void> _batchFetchWaterHeater(FetchWaterHeaterBatchStatusEvent event,
Emitter<WaterHeaterState> emit) async {
FutureOr<void> _batchFetchWaterHeater(FetchWaterHeaterBatchStatusEvent event, Emitter<WaterHeaterState> emit) async {
emit(WaterHeaterLoadingState());
try {
final status =
await DevicesManagementApi().getBatchStatus(event.devicesUuid);
deviceStatus = WaterHeaterStatusModel.fromJson(
event.devicesUuid.first, status.status);
final status = await DevicesManagementApi().getBatchStatus(event.devicesUuid);
deviceStatus = WaterHeaterStatusModel.fromJson(event.devicesUuid.first, status.status);
emit(WaterHeaterDeviceStatusLoaded(deviceStatus));
} catch (e) {
@@ -609,8 +621,7 @@ class WaterHeaterBloc extends Bloc<WaterHeaterEvent, WaterHeaterState> {
}
}
FutureOr<void> _batchControlWaterHeater(ControlWaterHeaterBatchEvent event,
Emitter<WaterHeaterState> emit) async {
FutureOr<void> _batchControlWaterHeater(ControlWaterHeaterBatchEvent event, Emitter<WaterHeaterState> emit) async {
if (state is WaterHeaterDeviceStatusLoaded) {
final currentState = state as WaterHeaterDeviceStatusLoaded;
@@ -71,6 +71,22 @@ final class AddScheduleEvent extends WaterHeaterEvent {
List<Object?> get props => [selectedDays, time, functionOn, category];
}
class EditWaterHeaterScheduleEvent extends WaterHeaterEvent {
final String scheduleId;
final String category;
final TimeOfDay time;
final bool functionOn;
final List<bool> selectedDays;
const EditWaterHeaterScheduleEvent({
required this.scheduleId,
required this.category,
required this.time,
required this.functionOn,
required this.selectedDays,
});
}
final class DeleteScheduleEvent extends WaterHeaterEvent {
final int index;
final String scheduleId;
@@ -1,14 +1,13 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
import 'package:syncrow_web/pages/device_managment/water_heater/bloc/water_heater_bloc.dart';
import 'package:syncrow_web/pages/device_managment/water_heater/models/schedule_model.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/extension/build_context_x.dart';
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
class ScheduleDialogHelper {
static void showAddScheduleDialog(BuildContext context,
{ScheduleModel? schedule, int? index, bool? isEdit}) {
static void showAddScheduleDialog(BuildContext context, {ScheduleModel? schedule, int? index, bool? isEdit}) {
final bloc = context.read<WaterHeaterBloc>();
if (schedule == null) {
@@ -70,35 +69,30 @@ class ScheduleDialogHelper {
padding: 8,
backgroundColor: ColorsManager.boxColor,
borderRadius: 15,
onPressed: isEdit == true
? null
: () async {
TimeOfDay? time = await showTimePicker(
context: context,
initialTime:
state.selectedTime ?? TimeOfDay.now(),
builder: (context, child) {
return Theme(
data: Theme.of(context).copyWith(
colorScheme: const ColorScheme.light(
primary: ColorsManager.primaryColor,
),
),
child: child!,
);
},
);
if (time != null) {
bloc.add(UpdateSelectedTimeEvent(time));
}
},
onPressed: () async {
TimeOfDay? time = await showTimePicker(
context: context,
initialTime: state.selectedTime ?? TimeOfDay.now(),
builder: (context, child) {
return Theme(
data: Theme.of(context).copyWith(
colorScheme: const ColorScheme.light(
primary: ColorsManager.primaryColor,
),
),
child: child!,
);
},
);
if (time != null) {
bloc.add(UpdateSelectedTimeEvent(time));
}
},
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
state.selectedTime == null
? 'Time'
: state.selectedTime!.format(context),
state.selectedTime == null ? 'Time' : state.selectedTime!.format(context),
style: context.textTheme.bodySmall!.copyWith(
color: ColorsManager.grayColor,
),
@@ -113,8 +107,7 @@ class ScheduleDialogHelper {
),
),
const SizedBox(height: 16),
_buildDayCheckboxes(context, state.selectedDays,
isEdit: isEdit),
_buildDayCheckboxes(context, state.selectedDays, isEdit: isEdit),
const SizedBox(height: 16),
_buildFunctionSwitch(context, state.functionOn, isEdit),
],
@@ -141,7 +134,13 @@ class ScheduleDialogHelper {
onPressed: () {
if (state.selectedTime != null) {
if (state.isEditing && index != null) {
return;
bloc.add(EditWaterHeaterScheduleEvent(
scheduleId: schedule?.scheduleId ?? '',
category: 'switch_1',
time: state.selectedTime!,
selectedDays: state.selectedDays,
functionOn: state.functionOn,
));
} else {
bloc.add(AddScheduleEvent(
category: 'switch_1',
@@ -193,9 +192,7 @@ class ScheduleDialogHelper {
return daysBoolean;
}
static Widget _buildDayCheckboxes(
BuildContext context, List<bool> selectedDays,
{bool? isEdit}) {
static Widget _buildDayCheckboxes(BuildContext context, List<bool> selectedDays, {bool? isEdit}) {
final dayLabels = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
return Row(
@@ -204,13 +201,9 @@ class ScheduleDialogHelper {
children: [
Checkbox(
value: selectedDays[index],
onChanged: isEdit == true
? null
: (bool? value) {
context
.read<WaterHeaterBloc>()
.add(UpdateSelectedDayEvent(index, value!));
},
onChanged: (bool? value) {
context.read<WaterHeaterBloc>().add(UpdateSelectedDayEvent(index, value!));
},
),
Text(dayLabels[index]),
],
@@ -219,27 +212,19 @@ class ScheduleDialogHelper {
);
}
static Widget _buildFunctionSwitch(
BuildContext context, bool isOn, bool? isEdit) {
static Widget _buildFunctionSwitch(BuildContext context, bool isOn, bool? isEdit) {
return Row(
children: [
Text(
'Function:',
style: context.textTheme.bodySmall!
.copyWith(color: ColorsManager.grayColor),
style: context.textTheme.bodySmall!.copyWith(color: ColorsManager.grayColor),
),
const SizedBox(width: 10),
Radio<bool>(
value: true,
groupValue: isOn,
onChanged: (bool? value) {
if (isEdit == true) {
return;
} else {
context
.read<WaterHeaterBloc>()
.add(const UpdateFunctionOnEvent(true));
}
context.read<WaterHeaterBloc>().add(const UpdateFunctionOnEvent(true));
},
),
const Text('On'),
@@ -248,13 +233,7 @@ class ScheduleDialogHelper {
value: false,
groupValue: isOn,
onChanged: (bool? value) {
if (isEdit == true) {
return;
} else {
context
.read<WaterHeaterBloc>()
.add(const UpdateFunctionOnEvent(false));
}
context.read<WaterHeaterBloc>().add(const UpdateFunctionOnEvent(false));
},
),
const Text('Off'),
@@ -1,7 +1,6 @@
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
class ScheduleEntry {
@@ -9,12 +8,14 @@ class ScheduleEntry {
final String time;
final Status function;
final List<String> days;
final String? scheduleId;
ScheduleEntry({
required this.category,
required this.time,
required this.function,
required this.days,
this.scheduleId,
});
@override
@@ -38,6 +39,7 @@ class ScheduleEntry {
Map<String, dynamic> toMap() {
return {
'scheduleId': scheduleId,
'category': category,
'time': time,
'function': function.toMap(),
@@ -56,8 +58,7 @@ class ScheduleEntry {
String toJson() => json.encode(toMap());
factory ScheduleEntry.fromJson(String source) =>
ScheduleEntry.fromMap(json.decode(source));
factory ScheduleEntry.fromJson(String source) => ScheduleEntry.fromMap(json.decode(source));
@override
bool operator ==(Object other) {
@@ -72,9 +73,6 @@ class ScheduleEntry {
@override
int get hashCode {
return category.hashCode ^
time.hashCode ^
function.hashCode ^
days.hashCode;
return category.hashCode ^ time.hashCode ^ function.hashCode ^ days.hashCode;
}
}
@@ -2,9 +2,18 @@ import 'package:flutter/material.dart';
import 'package:syncrow_web/pages/device_managment/shared/toggle_widget.dart';
import 'package:syncrow_web/utils/color_manager.dart';
class WaterLeakNotificationDialog extends StatelessWidget {
class WaterLeakNotificationDialog extends StatefulWidget {
const WaterLeakNotificationDialog({super.key});
@override
State<WaterLeakNotificationDialog> createState() => _NotificationDialogState();
}
class _NotificationDialogState extends State<WaterLeakNotificationDialog> {
bool isLowBatteryNotificationEnabled = true;
bool isClosingRemindersEnabled = true;
bool isWaterLeakage = true;
@override
Widget build(BuildContext context) {
return Dialog(
@@ -14,7 +23,7 @@ class WaterLeakNotificationDialog extends StatelessWidget {
borderRadius: BorderRadius.circular(20),
),
child: SizedBox(
width: 400,
width: 560,
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(20.0),
@@ -61,21 +70,37 @@ class WaterLeakNotificationDialog extends StatelessWidget {
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ToggleWidget(
value: true,
code: 'notification',
deviceId: '',
label: 'Low Battery',
onChange: (v) {},
icon: '-1',
SizedBox(
width: 170,
height: 135,
child: ToggleWidget(
value: isLowBatteryNotificationEnabled,
code: 'notification',
deviceId: '',
label: 'Low Battery',
onChange: (v) {
setState(() {
isLowBatteryNotificationEnabled = v;
});
},
icon: '-1',
),
),
ToggleWidget(
value: true,
code: 'notification',
deviceId: '',
label: 'Water Leakage',
onChange: (v) {},
icon: '-1',
SizedBox(
width: 170,
height: 135,
child: ToggleWidget(
value: isWaterLeakage,
code: 'notification',
deviceId: '',
label: 'Water Leakage',
onChange: (v) {
setState(() {
isWaterLeakage = v;
});
},
icon: '-1',
),
),
],
),
@@ -76,7 +76,8 @@ class VisitorPasswordBloc extends Bloc<VisitorPasswordEvent, VisitorPasswordStat
Future<void> selectTimeVisitorPassword(
SelectTimeVisitorPassword event,
Emitter<VisitorPasswordState> emit,) async {
Emitter<VisitorPasswordState> emit,
) async {
final DateTime? picked = await showDatePicker(
context: event.context,
initialDate: DateTime.now(),
@@ -359,7 +360,6 @@ class VisitorPasswordBloc extends Bloc<VisitorPasswordEvent, VisitorPasswordStat
context: event.context,
initialTime: TimeOfDay.now(),
);
print('timePicked=$timePicked');
if (timePicked != null) {
final selectedDateTime = DateTime(
@@ -1,6 +1,6 @@
import 'package:syncrow_web/utils/constants/app_enum.dart';
import 'package:syncrow_web/utils/constants/assets.dart';
import 'package:syncrow_web/utils/enum/device_types.dart';
import 'package:syncrow_web/utils/constants/app_enum.dart';
class DeviceModel {
dynamic productUuid;
@@ -51,7 +51,6 @@ class DeviceModel {
factory DeviceModel.fromJson(Map<String, dynamic> json) {
String tempIcon = '';
DeviceType type = devicesTypesMap[json['productType']] ?? DeviceType.Other;
if (type == DeviceType.LightBulb) {
tempIcon = Assets.lightBulb;
} else if (type == DeviceType.CeilingSensor || type == DeviceType.WallSensor) {
@@ -66,9 +65,22 @@ class DeviceModel {
tempIcon = Assets.gangSwitch;
} else if (type == DeviceType.Gateway) {
tempIcon = Assets.gateway;
} else if (type == DeviceType.OneGang) {
tempIcon = Assets.oneGang;
} else if (type == DeviceType.TwoGang) {
tempIcon = Assets.twoGang;
} else if (type == DeviceType.WH) {
tempIcon = Assets.waterHeater;
} else if (type == DeviceType.DoorSensor) {
tempIcon = Assets.openCloseDoor;
} else if (type == DeviceType.GarageDoor) {
tempIcon = Assets.openedDoor;
} else if (type == DeviceType.WaterLeak) {
tempIcon = Assets.waterLeakNormal;
} else {
tempIcon = Assets.logo;
tempIcon = Assets.blackLogo;
}
return DeviceModel(
productUuid: json['productUuid'],
productType: json['productType'],
-1
View File
@@ -12,7 +12,6 @@ class AccessMangApi {
path: ApiEndpoints.visitorPassword,
showServerMessage: true,
expectedResponseModel: (json) {
print(json);
List<dynamic> jsonData = json;
List<PasswordModel> passwordList = jsonData.map((jsonItem) {
return PasswordModel.fromJson(jsonItem);
+24 -20
View File
@@ -68,8 +68,7 @@ class DevicesManagementApi {
}
}
Future<bool> deviceBatchControl(
List<String> uuids, String code, dynamic value) async {
Future<bool> deviceBatchControl(List<String> uuids, String code, dynamic value) async {
try {
final body = {
'devicesUuid': uuids,
@@ -93,8 +92,7 @@ class DevicesManagementApi {
}
}
static Future<List<DeviceModel>> getDevicesByGatewayId(
String gatewayId) async {
static Future<List<DeviceModel>> getDevicesByGatewayId(String gatewayId) async {
final response = await HTTPService().get(
path: ApiEndpoints.gatewayApi.replaceAll('{gatewayUuid}', gatewayId),
showServerMessage: false,
@@ -128,9 +126,7 @@ class DevicesManagementApi {
String code,
) async {
final response = await HTTPService().get(
path: ApiEndpoints.getDeviceLogs
.replaceAll('{uuid}', uuid)
.replaceAll('{code}', code),
path: ApiEndpoints.getDeviceLogs.replaceAll('{uuid}', uuid).replaceAll('{code}', code),
showServerMessage: false,
expectedResponseModel: (json) {
return DeviceReport.fromJson(json);
@@ -139,8 +135,7 @@ class DevicesManagementApi {
return response;
}
static Future<DeviceReport> getDeviceReportsByDate(String uuid, String code,
[String? from, String? to]) async {
static Future<DeviceReport> getDeviceReportsByDate(String uuid, String code, [String? from, String? to]) async {
final response = await HTTPService().get(
path: ApiEndpoints.getDeviceLogsByDate
.replaceAll('{uuid}', uuid)
@@ -179,8 +174,7 @@ class DevicesManagementApi {
}
}
Future<bool> addScheduleRecord(
ScheduleEntry sendSchedule, String uuid) async {
Future<bool> addScheduleRecord(ScheduleEntry sendSchedule, String uuid) async {
try {
final response = await HTTPService().post(
path: ApiEndpoints.scheduleByDeviceId.replaceAll('{deviceUuid}', uuid),
@@ -197,13 +191,10 @@ class DevicesManagementApi {
}
}
Future<List<ScheduleModel>> getDeviceSchedules(
String uuid, String category) async {
Future<List<ScheduleModel>> getDeviceSchedules(String uuid, String category) async {
try {
final response = await HTTPService().get(
path: ApiEndpoints.getScheduleByDeviceId
.replaceAll('{deviceUuid}', uuid)
.replaceAll('{category}', category),
path: ApiEndpoints.getScheduleByDeviceId.replaceAll('{deviceUuid}', uuid).replaceAll('{category}', category),
showServerMessage: true,
expectedResponseModel: (json) {
List<ScheduleModel> schedules = [];
@@ -220,10 +211,7 @@ class DevicesManagementApi {
}
}
Future<bool> updateScheduleRecord(
{required bool enable,
required String uuid,
required String scheduleId}) async {
Future<bool> updateScheduleRecord({required bool enable, required String uuid, required String scheduleId}) async {
try {
final response = await HTTPService().put(
path: ApiEndpoints.updateScheduleByDeviceId
@@ -244,6 +232,22 @@ class DevicesManagementApi {
}
}
Future<bool> editScheduleRecord(String uuid, ScheduleEntry newSchedule) async {
try {
final response = await HTTPService().put(
path: ApiEndpoints.scheduleByDeviceId.replaceAll('{deviceUuid}', uuid),
body: newSchedule.toMap(),
expectedResponseModel: (json) {
return json['success'] ?? false;
},
);
return response;
} catch (e) {
debugPrint('Error fetching $e');
return false;
}
}
Future<bool> deleteScheduleRecord(String uuid, String scheduleId) async {
try {
final response = await HTTPService().delete(
+1 -2
View File
@@ -5,8 +5,7 @@ abstract class ColorsManager {
static const Color switchOffColor = Color(0x7F8D99AE);
static const Color primaryColor = Color(0xFF0030CB); //023DFE
static const Color secondaryTextColor = Color(0xFF848484);
static Color primaryColorWithOpacity =
const Color(0xFF023DFE).withOpacity(0.6);
static Color primaryColorWithOpacity = const Color(0xFF023DFE).withOpacity(0.6);
static const Color whiteColors = Colors.white;
static const Color secondaryColor = Color(0xFF023DFE);
static const Color onSecondaryColor = Color(0xFF023DFE);
+32 -52
View File
@@ -13,12 +13,10 @@ class Assets {
static const String rightLine = "assets/images/right_line.png";
static const String google = "assets/images/google.svg";
static const String facebook = "assets/images/facebook.svg";
static const String invisiblePassword =
"assets/images/Password_invisible.svg";
static const String invisiblePassword = "assets/images/Password_invisible.svg";
static const String visiblePassword = "assets/images/password_visible.svg";
static const String accessIcon = "assets/images/access_icon.svg";
static const String spaseManagementIcon =
"assets/images/spase_management_icon.svg";
static const String spaseManagementIcon = "assets/images/spase_management_icon.svg";
static const String devicesIcon = "assets/images/devices_icon.svg";
static const String moveinIcon = "assets/images/movein_icon.svg";
static const String constructionIcon = "assets/images/construction_icon.svg";
@@ -31,15 +29,13 @@ class Assets {
static const String emptyTable = "assets/images/empty_table.svg";
// General assets
static const String motionlessDetection =
"assets/icons/motionless_detection.svg";
static const String motionlessDetection = "assets/icons/motionless_detection.svg";
static const String acHeating = "assets/icons/ac_heating.svg";
static const String acPowerOff = "assets/icons/ac_power_off.svg";
static const String acFanMiddle = "assets/icons/ac_fan_middle.svg";
static const String switchAlarmSound = "assets/icons/switch_alarm_sound.svg";
static const String resetOff = "assets/icons/reset_off.svg";
static const String sensitivityOperationIcon =
"assets/icons/sesitivity_operation_icon.svg";
static const String sensitivityOperationIcon = "assets/icons/sesitivity_operation_icon.svg";
static const String motionDetection = "assets/icons/motion_detection.svg";
static const String freezing = "assets/icons/freezing.svg";
static const String indicator = "assets/icons/indicator.svg";
@@ -60,56 +56,35 @@ class Assets {
static const String celsiusDegrees = "assets/icons/celsius_degrees.svg";
static const String masterState = "assets/icons/master_state.svg";
static const String acPower = "assets/icons/ac_power.svg";
static const String farDetectionFunction =
"assets/icons/far_detection_function.svg";
static const String farDetectionFunction = "assets/icons/far_detection_function.svg";
static const String nobodyTime = "assets/icons/nobody_time.svg";
// Automation functions
static const String tempPasswordUnlock =
"assets/icons/automation_functions/temp_password_unlock.svg";
static const String doorlockNormalOpen =
"assets/icons/automation_functions/doorlock_normal_open.svg";
static const String doorbell =
"assets/icons/automation_functions/doorbell.svg";
static const String remoteUnlockViaApp =
"assets/icons/automation_functions/remote_unlock_via_app.svg";
static const String doubleLock =
"assets/icons/automation_functions/double_lock.svg";
static const String selfTestResult =
"assets/icons/automation_functions/self_test_result.svg";
static const String lockAlarm =
"assets/icons/automation_functions/lock_alarm.svg";
static const String presenceState =
"assets/icons/automation_functions/presence_state.svg";
static const String currentTemp =
"assets/icons/automation_functions/current_temp.svg";
static const String presence =
"assets/icons/automation_functions/presence.svg";
static const String residualElectricity =
"assets/icons/automation_functions/residual_electricity.svg";
static const String hijackAlarm =
"assets/icons/automation_functions/hijack_alarm.svg";
static const String passwordUnlock =
"assets/icons/automation_functions/password_unlock.svg";
static const String remoteUnlockRequest =
"assets/icons/automation_functions/remote_unlock_req.svg";
static const String cardUnlock =
"assets/icons/automation_functions/card_unlock.svg";
static const String tempPasswordUnlock = "assets/icons/automation_functions/temp_password_unlock.svg";
static const String doorlockNormalOpen = "assets/icons/automation_functions/doorlock_normal_open.svg";
static const String doorbell = "assets/icons/automation_functions/doorbell.svg";
static const String remoteUnlockViaApp = "assets/icons/automation_functions/remote_unlock_via_app.svg";
static const String doubleLock = "assets/icons/automation_functions/double_lock.svg";
static const String selfTestResult = "assets/icons/automation_functions/self_test_result.svg";
static const String lockAlarm = "assets/icons/automation_functions/lock_alarm.svg";
static const String presenceState = "assets/icons/automation_functions/presence_state.svg";
static const String currentTemp = "assets/icons/automation_functions/current_temp.svg";
static const String presence = "assets/icons/automation_functions/presence.svg";
static const String residualElectricity = "assets/icons/automation_functions/residual_electricity.svg";
static const String hijackAlarm = "assets/icons/automation_functions/hijack_alarm.svg";
static const String passwordUnlock = "assets/icons/automation_functions/password_unlock.svg";
static const String remoteUnlockRequest = "assets/icons/automation_functions/remote_unlock_req.svg";
static const String cardUnlock = "assets/icons/automation_functions/card_unlock.svg";
static const String motion = "assets/icons/automation_functions/motion.svg";
static const String fingerprintUnlock =
"assets/icons/automation_functions/fingerprint_unlock.svg";
static const String fingerprintUnlock = "assets/icons/automation_functions/fingerprint_unlock.svg";
// Presence Sensor Assets
static const String sensorMotionIcon = "assets/icons/sensor_motion_ic.svg";
static const String sensorPresenceIcon =
"assets/icons/sensor_presence_ic.svg";
static const String sensorPresenceIcon = "assets/icons/sensor_presence_ic.svg";
static const String sensorVacantIcon = "assets/icons/sensor_vacant_ic.svg";
static const String illuminanceRecordIcon =
"assets/icons/illuminance_record_ic.svg";
static const String presenceRecordIcon =
"assets/icons/presence_record_ic.svg";
static const String helpDescriptionIcon =
"assets/icons/help_description_ic.svg";
static const String illuminanceRecordIcon = "assets/icons/illuminance_record_ic.svg";
static const String presenceRecordIcon = "assets/icons/presence_record_ic.svg";
static const String helpDescriptionIcon = "assets/icons/help_description_ic.svg";
static const String lightPulp = "assets/icons/light_pulb.svg";
static const String acDevice = "assets/icons/ac_device.svg";
@@ -183,9 +158,14 @@ class Assets {
//assets/icons/water_leak_normal.svg
static const String waterLeakNormal = 'assets/icons/water_leak_normal.svg';
//assets/icons/water_leak_detected.svg
static const String waterLeakDetected =
'assets/icons/water_leak_detected.svg';
static const String waterLeakDetected = 'assets/icons/water_leak_detected.svg';
//assets/icons/automation_records.svg
static const String automationRecords = 'assets/icons/automation_records.svg';
//assets/icons/1gang.svg
static const String oneGang = 'assets/icons/1gang.svg';
//assets/icons/2gang.svg
static const String twoGang = 'assets/icons/2gang.svg';
}
+35
View File
@@ -4,12 +4,37 @@ enum DeviceType {
DoorLock,
Curtain,
Blind,
OneGang,
TwoGang,
ThreeGang,
Gateway,
CeilingSensor,
WallSensor,
WH,
DoorSensor,
GarageDoor,
WaterLeak,
Other,
}
/*
3G:
1G:
2G:
GW:
DL:
WPS:
CPS:
AC:
CUR:
WH:
DS:
1GT:
2GT:
3GT:
GD:
WL:
*/
Map<String, DeviceType> devicesTypesMap = {
"AC": DeviceType.AC,
@@ -18,4 +43,14 @@ Map<String, DeviceType> devicesTypesMap = {
"DL": DeviceType.DoorLock,
"WPS": DeviceType.WallSensor,
"3G": DeviceType.ThreeGang,
"2G": DeviceType.TwoGang,
"1G": DeviceType.OneGang,
"CUR": DeviceType.Curtain,
"WH": DeviceType.WH,
'DS': DeviceType.DoorSensor,
"1GT": DeviceType.OneGang,
"2GT": DeviceType.TwoGang,
"3GT": DeviceType.ThreeGang,
'GD': DeviceType.GarageDoor,
'WL': DeviceType.WaterLeak
};