push main door device design

This commit is contained in:
ashrafzarkanisala
2024-09-18 01:36:17 +03:00
parent 7d5b5340db
commit 9876ff2e03
10 changed files with 520 additions and 1 deletions

View File

@ -0,0 +1,23 @@
<svg width="29" height="38" viewBox="0 0 29 38" fill="none" xmlns="http://www.w3.org/2000/svg">
<g filter="url(#filter0_i_2351_2766)">
<path d="M0 5.18168C0 2.69345 1.82822 0.560776 4.30407 0.312864C8.58098 -0.115392 11.9929 -0.0966095 16.2213 0.32393C18.7091 0.57135 20.5548 2.70894 20.5548 5.20899V32.7835C20.5548 35.246 18.7637 37.3665 16.3165 37.6408C12.0557 38.1183 8.5855 38.1222 4.24256 37.6376C1.79332 37.3643 0 35.2435 0 32.7791V5.18168Z" fill="#EAF6FF"/>
</g>
<path d="M17.5761 23.3577C17.7051 23.3577 17.8341 23.3086 17.9325 23.2102C18.1293 23.0133 18.1293 22.6943 17.9325 22.4975C16.2479 20.813 16.2479 18.0721 17.9325 16.3875C18.1293 16.1907 18.1293 15.8717 17.9325 15.6749C17.7356 15.4782 17.4166 15.4782 17.2198 15.6749C15.1423 17.7525 15.1423 21.1327 17.2198 23.2103C17.3182 23.3086 17.4472 23.3577 17.5761 23.3577Z" fill="#8AC9FE"/>
<path d="M18.6358 21.4001C18.744 21.4001 18.8522 21.3588 18.9348 21.2762C19.0999 21.1111 19.0999 20.8434 18.9347 20.6783C18.6046 20.3483 18.4228 19.9093 18.4228 19.4424C18.4228 18.9756 18.6046 18.5367 18.9347 18.2066C19.0999 18.0415 19.0999 17.7738 18.9348 17.6087C18.7696 17.4436 18.5019 17.4436 18.3369 17.6087C17.847 18.0985 17.5772 18.7497 17.5772 19.4424C17.5772 20.1352 17.847 20.7864 18.3369 21.2763C18.4193 21.3587 18.5276 21.4001 18.6358 21.4001Z" fill="#8AC9FE"/>
<path d="M11.1713 30.5347L11.1713 32.4539C11.1713 32.8359 10.8617 33.1455 10.4797 33.1455C10.0976 33.1455 9.78809 32.8359 9.78809 32.4539L9.78809 30.5347C9.78809 30.1527 10.0976 29.8431 10.4797 29.8431C10.8617 29.8431 11.1713 30.1527 11.1713 30.5347Z" fill="#B3DAFE"/>
<path d="M21.5342 8.79642C21.5342 7.91189 22.1118 7.11379 22.9777 6.93351C24.3924 6.63901 25.5238 6.65107 26.9209 6.93884C27.7961 7.1191 28.3858 7.92191 28.3858 8.81547V31.0421C28.3858 31.9071 27.8339 32.6929 26.9918 32.8912C25.5575 33.2289 24.3936 33.2319 22.9318 32.8895C22.0881 32.6918 21.5342 31.9055 21.5342 31.039V8.79642Z" fill="#EAF6FF"/>
<path d="M23.9952 23.3577C23.8662 23.3577 23.7372 23.3086 23.6388 23.2102C23.442 23.0133 23.442 22.6943 23.6388 22.4975C25.3234 20.813 25.3234 18.0721 23.6388 16.3875C23.442 16.1907 23.442 15.8717 23.6388 15.6749C23.8357 15.4782 24.1547 15.4782 24.3515 15.6749C26.429 17.7525 26.429 21.1327 24.3515 23.2103C24.2531 23.3086 24.1241 23.3577 23.9952 23.3577Z" fill="#8AC9FE"/>
<path d="M22.9355 21.4001C22.8273 21.4001 22.7191 21.3588 22.6365 21.2762C22.4714 21.1111 22.4714 20.8434 22.6366 20.6783C22.9666 20.3483 23.1485 19.9093 23.1485 19.4424C23.1485 18.9756 22.9666 18.5367 22.6366 18.2066C22.4714 18.0415 22.4714 17.7738 22.6365 17.6087C22.8017 17.4436 23.0694 17.4436 23.2344 17.6087C23.7243 18.0985 23.9941 18.7497 23.9941 19.4424C23.9941 20.1352 23.7243 20.7864 23.2344 21.2763C23.1519 21.3587 23.0437 21.4001 22.9355 21.4001Z" fill="#8AC9FE"/>
<defs>
<filter id="filter0_i_2351_2766" x="-1" y="0" width="21.5547" height="38" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
<feFlood flood-opacity="0" result="BackgroundImageFix"/>
<feBlend mode="normal" in="SourceGraphic" in2="BackgroundImageFix" result="shape"/>
<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha"/>
<feOffset dx="-1"/>
<feGaussianBlur stdDeviation="1.5"/>
<feComposite in2="hardAlpha" operator="arithmetic" k2="-1" k3="1"/>
<feColorMatrix type="matrix" values="0 0 0 0 0.538295 0 0 0 0 0.538295 0 0 0 0 0.538295 0 0 0 0.3 0"/>
<feBlend mode="normal" in2="shape" result="effect1_innerShadow_2351_2766"/>
</filter>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

@ -0,0 +1,10 @@
<svg width="31" height="35" viewBox="0 0 31 35" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M17.4316 6.37335C16.8654 6.37335 16.4062 5.91425 16.4062 5.34796V3.07617C16.4062 2.51077 15.9463 2.05078 15.3809 2.05078C14.8155 2.05078 14.3555 2.51077 14.3555 3.07617V5.34796C14.3555 5.91425 13.8964 6.37335 13.3301 6.37335C12.7638 6.37335 12.3047 5.91425 12.3047 5.34796V3.07617C12.3047 1.37997 13.6847 0 15.3809 0C17.0771 0 18.457 1.37997 18.457 3.07617V5.34796C18.457 5.91425 17.9979 6.37335 17.4316 6.37335Z" fill="#FFB454"/>
<path d="M16.4062 3.07617V5.34796C16.4062 5.91425 16.8654 6.37335 17.4316 6.37335C17.9979 6.37335 18.457 5.91425 18.457 5.34796V3.07617C18.457 1.37997 17.0771 0 15.3809 0V2.05078C15.9463 2.05078 16.4062 2.51077 16.4062 3.07617Z" fill="#FF8E00"/>
<path d="M15.3809 35C12.5539 35 10.2539 32.7 10.2539 29.873C10.2539 29.3068 10.713 28.8477 11.2793 28.8477H19.4824C20.0487 28.8477 20.5078 29.3068 20.5078 29.873C20.5078 32.7 18.2079 35 15.3809 35Z" fill="#FFB454"/>
<path d="M19.4824 28.8477H15.3809V35C18.2079 35 20.5078 32.7 20.5078 29.873C20.5078 29.3068 20.0487 28.8477 19.4824 28.8477Z" fill="#FF8E00"/>
<path d="M29.7363 30.8984H1.0254C0.614562 30.8984 0.243439 30.6532 0.0822478 30.2753C-0.0789436 29.8975 0.000968566 29.4599 0.285344 29.1633C3.18706 26.1372 4.78517 22.1616 4.78517 17.9691V14.6973C4.78517 8.85479 9.5384 4.10156 15.3809 4.10156C21.2233 4.10156 25.9766 8.85479 25.9766 14.6973V17.9691C25.9766 22.1617 27.5747 26.1372 30.4765 29.1633C30.7608 29.4599 30.8407 29.8975 30.6795 30.2753C30.5184 30.6532 30.1472 30.8984 29.7363 30.8984Z" fill="#FFE278"/>
<path d="M29.7363 30.8984C30.1472 30.8984 30.5183 30.6532 30.6795 30.2753C30.8407 29.8975 30.7608 29.4599 30.4765 29.1633C27.5747 26.1372 25.9766 22.1616 25.9766 17.9691V14.6973C25.9766 8.85479 21.2233 4.10156 15.3809 4.10156V30.8984H29.7363Z" fill="#FFB454"/>
<path d="M29.7359 15.7226C29.1696 15.7226 28.7105 15.2635 28.7105 14.6972C28.7105 11.1366 27.3239 7.78912 24.8062 5.27144C24.4057 4.87099 24.4057 4.22178 24.8062 3.82133C25.2066 3.42088 25.8559 3.42088 26.2563 3.82133C29.1614 6.72633 30.7613 10.5888 30.7613 14.6972C30.7613 15.2635 30.3022 15.7226 29.7359 15.7226Z" fill="#08475E"/>
<path d="M1.02539 15.7226C0.459102 15.7226 0 15.2635 0 14.6972C0 10.5888 1.59988 6.7264 4.50495 3.82133C4.90533 3.42088 5.55461 3.42088 5.95506 3.82133C6.35551 4.22178 6.35551 4.87099 5.95506 5.27144C3.43738 7.78918 2.05078 11.1367 2.05078 14.6972C2.05078 15.2635 1.59168 15.7226 1.02539 15.7226Z" fill="#0A789B"/>
</svg>

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -0,0 +1,18 @@
<svg width="35" height="35" viewBox="0 0 35 35" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M4.62771 22.7848L0.0206433 9.97422C-0.0455284 9.78766 0.0527038 9.58101 0.239256 9.51286C6.29643 7.33432 13.1218 5.30816 18.9563 2.81865C19.2171 2.65418 19.4217 2.81667 19.534 3.12757L26.7725 21.7858L28.7381 27.2523C28.8043 27.4388 28.7081 27.6475 28.5215 27.7137L14.6702 32.6947L9.27087 34.6366C9.08432 34.7048 8.87774 34.6065 8.80958 34.4199L4.62771 22.7848Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M8.46894 18.5338L6.16844 5.11738C6.13433 4.92078 6.26674 4.73423 6.46129 4.70012L22.3042 1.98393L25.9325 1.38613C26.1311 1.29986 26.454 1.40015 26.5302 1.84352L30.4493 21.4146L31.4301 27.1398C31.4642 27.3345 31.3318 27.523 31.1372 27.5571L16.6301 30.0446L10.974 31.0155C10.7795 31.0477 10.5909 30.9152 10.5568 30.7206L8.46894 18.5338Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M12.9063 14.5779V27.4768C12.9063 27.6835 13.0748 27.854 13.2814 27.854H19.2684H28.1315H29.4051H34.624C34.8305 27.854 34.999 27.6835 34.999 27.4768V21.4166V4.67611V4.50159H31.1882C30.8212 4.50159 30.059 4.55375 30.059 3.72127L30.0509 0H13.2813C13.0748 0 12.9062 0.168505 12.9062 0.375155V3.59487V4.957V14.5779H12.9063Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M6.54915 7.34229C4.40308 8.0645 2.27704 8.78063 0.239256 9.51283C0.0527037 9.58105 -0.0455284 9.78763 0.0206433 9.97418L4.62771 22.7848L8.80958 34.4199C8.87781 34.6065 9.08439 34.7048 9.27087 34.6365L14.6702 32.6947L26.9732 28.2713L6.54915 7.34229Z" fill="#B5C4CF"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M12.9076 3.59473L6.46129 4.70003C6.26674 4.73414 6.13433 4.92069 6.16844 5.11729L6.54955 7.34197L8.469 18.5337L10.5569 30.7205C10.591 30.9151 10.7795 31.0474 10.9741 31.0154L16.6301 30.0445L26.9735 28.2711L29.4064 27.8538H28.1328L12.9076 3.59473Z" fill="#D7E7EC"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M34.999 21.4166V4.67611V4.50159V4.44342C34.999 4.33507 34.9528 4.31702 34.7864 4.15453L30.6727 0.230712C30.4782 0.0461424 30.4461 0 30.3318 0H30.0509H13.2813C13.0748 0 12.9062 0.168505 12.9062 0.375155V27.4768C12.9062 27.6835 13.0748 27.854 13.2813 27.854H34.6239C34.8305 27.854 34.999 27.6835 34.999 27.4768V21.4166Z" fill="#EDF3F4"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M12.9077 3.59473L11.3975 3.85353V28.8629C11.3975 29.0716 11.566 29.2401 11.7725 29.2401H17.7595H21.3216L26.9736 28.2712L29.4065 27.8539H28.1329H26.5665H19.2698H13.2828C13.0762 27.8539 12.9077 27.6834 12.9077 27.4768C12.9077 19.5167 12.9077 11.5547 12.9077 3.59473Z" fill="#B5C4CF"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M8.46896 18.5336L6.54951 7.3418C6.03005 7.51632 5.51257 7.69084 4.99707 7.86536L5.23578 9.25558L7.15524 20.4473L9.24518 32.6341C9.27724 32.8286 9.46578 32.961 9.66033 32.929L15.3164 31.9581L18 31.4987L26.0829 28.59L25.9867 28.4395L21.3214 29.2399L16.6302 30.0444L10.9741 31.0153C10.7796 31.0474 10.591 30.915 10.5569 30.7204L8.46896 18.5336Z" fill="#9AAFB7"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M34.9998 21.4166V4.67611V4.50159C34.9998 4.29897 34.9337 4.29699 34.7873 4.15453L30.6736 0.230712C30.4791 0.0461424 30.447 0 30.3326 0H30.0518H25.8779C30.9784 6.8286 31.2692 19.1377 27.4845 26.8209C27.31 27.178 27.1275 27.521 26.937 27.854H28.1323H29.4059H34.6248C34.8313 27.854 34.9998 27.6835 34.9998 27.4768V21.4166Z" fill="#D7E7EC"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M30.0607 3.72127C30.0607 4.55375 30.8229 4.50159 31.19 4.50159H35.0008V4.44342C35.0008 4.33507 34.9546 4.31702 34.7882 4.15453L30.6745 0.230712C30.48 0.0461424 30.4479 0 30.3336 0H30.0527L30.0607 3.72127Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M34.7882 4.15453L30.6745 0.230712C30.48 0.0461424 30.4479 0 30.3336 0H30.0527L30.0607 3.7212C30.0607 4.55368 30.8229 4.50152 31.19 4.50152H35.0008V4.44335C35.0008 4.33507 34.9546 4.31702 34.7882 4.15453Z" fill="#B5C4CF"/>
<path d="M31.6094 8.20367H16.5086C16.2169 8.20367 15.9805 7.96715 15.9805 7.67532C15.9805 7.3835 16.2169 7.14697 16.5086 7.14697H31.6094C31.9011 7.14697 32.1376 7.3835 32.1376 7.67532C32.1376 7.96715 31.9012 8.20367 31.6094 8.20367Z" fill="#9AAFB7"/>
<path d="M31.6094 11.9566H16.5086C16.2169 11.9566 15.9805 11.7201 15.9805 11.4283C15.9805 11.1364 16.2169 10.8999 16.5086 10.8999H31.6094C31.9011 10.8999 32.1376 11.1364 32.1376 11.4283C32.1376 11.7201 31.9012 11.9566 31.6094 11.9566Z" fill="#9AAFB7"/>
<path d="M31.6094 15.7105H16.5086C16.2169 15.7105 15.9805 15.474 15.9805 15.1822C15.9805 14.8903 16.2169 14.6538 16.5086 14.6538H31.6094C31.9011 14.6538 32.1376 14.8903 32.1376 15.1822C32.1376 15.474 31.9012 15.7105 31.6094 15.7105Z" fill="#9AAFB7"/>
<path d="M31.6094 19.4634H16.5086C16.2169 19.4634 15.9805 19.2269 15.9805 18.9351C15.9805 18.6433 16.2169 18.4067 16.5086 18.4067H31.6094C31.9011 18.4067 32.1376 18.6433 32.1376 18.9351C32.1376 19.2269 31.9012 19.4634 31.6094 19.4634Z" fill="#9AAFB7"/>
<path d="M31.6094 23.2169H16.5086C16.2169 23.2169 15.9805 22.9803 15.9805 22.6885C15.9805 22.3967 16.2169 22.1602 16.5086 22.1602H31.6094C31.9011 22.1602 32.1376 22.3967 32.1376 22.6885C32.1376 22.9803 31.9012 23.2169 31.6094 23.2169Z" fill="#9AAFB7"/>
</svg>

After

Width:  |  Height:  |  Size: 5.1 KiB

View File

@ -11,6 +11,7 @@ import 'package:syncrow_web/pages/device_managment/door_lock/view/door_lock_batc
import 'package:syncrow_web/pages/device_managment/door_lock/view/door_lock_control_view.dart'; import 'package:syncrow_web/pages/device_managment/door_lock/view/door_lock_control_view.dart';
import 'package:syncrow_web/pages/device_managment/gateway/view/gateway_batch_control.dart'; import 'package:syncrow_web/pages/device_managment/gateway/view/gateway_batch_control.dart';
import 'package:syncrow_web/pages/device_managment/gateway/view/gateway_view.dart'; import 'package:syncrow_web/pages/device_managment/gateway/view/gateway_view.dart';
import 'package:syncrow_web/pages/device_managment/main_door_sensor/view/main_door_control_view.dart';
import 'package:syncrow_web/pages/device_managment/one_gang_switch/view/wall_light_batch_control.dart'; import 'package:syncrow_web/pages/device_managment/one_gang_switch/view/wall_light_batch_control.dart';
import 'package:syncrow_web/pages/device_managment/one_gang_switch/view/wall_light_device_control.dart'; import 'package:syncrow_web/pages/device_managment/one_gang_switch/view/wall_light_device_control.dart';
import 'package:syncrow_web/pages/device_managment/three_gang_switch/view/living_room_batch_controls.dart'; import 'package:syncrow_web/pages/device_managment/three_gang_switch/view/living_room_batch_controls.dart';
@ -55,7 +56,11 @@ mixin RouteControlsBasedCode {
case 'AC': case 'AC':
return AcDeviceControlsView(device: device); return AcDeviceControlsView(device: device);
case 'WH': case 'WH':
return WaterHeaterDeviceControl(device: device,); return WaterHeaterDeviceControl(
device: device,
);
case 'DS':
return MainDoorSensorControlView(device: device);
default: default:
return const SizedBox(); return const SizedBox();
} }

View File

@ -0,0 +1,139 @@
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/main_door_sensor/bloc/main_door_sensor_event.dart';
import 'package:syncrow_web/pages/device_managment/main_door_sensor/bloc/main_door_sensor_state.dart';
import 'package:syncrow_web/pages/device_managment/main_door_sensor/models/main_door_status_model.dart';
import 'package:syncrow_web/services/devices_mang_api.dart';
class MainDoorSensorBloc
extends Bloc<MainDoorSensorEvent, MainDoorSensorState> {
MainDoorSensorBloc() : super(MainDoorSensorInitial()) {
on<MainDoorSensorFetchDeviceEvent>(_onFetchDeviceStatus);
on<MainDoorSensorControl>(_onControl);
on<MainDoorSensorFetchBatchEvent>(_onFetchBatchStatus);
on<MainDoorSensorReportsEvent>(_fetchReports);
}
late MainDoorSensorStatusModel deviceStatus;
Timer? _timer;
FutureOr<void> _onFetchDeviceStatus(MainDoorSensorFetchDeviceEvent event,
Emitter<MainDoorSensorState> emit) async {
emit(MainDoorSensorLoadingState());
try {
final status = await DevicesManagementApi()
.getDeviceStatus(event.deviceId)
.then((value) => value.status);
deviceStatus = MainDoorSensorStatusModel.fromJson(event.deviceId, status);
emit(MainDoorSensorDeviceStatusLoaded(deviceStatus));
} catch (e) {
emit(MainDoorSensorFailedState(error: e.toString()));
}
}
FutureOr<void> _onControl(
MainDoorSensorControl event, Emitter<MainDoorSensorState> emit) async {
final oldValue = _getValueByCode(event.code);
_updateLocalValue(event.code, event.value);
emit(MainDoorSensorDeviceStatusLoaded(deviceStatus));
await _runDebounce(
deviceId: event.deviceId,
code: event.code,
value: event.value,
oldValue: oldValue,
emit: emit,
);
}
Future<void> _runDebounce({
required String deviceId,
required String code,
required bool value,
required bool oldValue,
required Emitter<MainDoorSensorState> emit,
}) async {
if (_timer != null) {
_timer!.cancel();
}
_timer = Timer(const Duration(milliseconds: 500), () async {
try {
final status = await DevicesManagementApi()
.deviceControl(deviceId, Status(code: code, value: value));
if (!status) {
_revertValueAndEmit(deviceId, code, oldValue, emit);
}
emit(MainDoorSensorDeviceStatusLoaded(deviceStatus));
} catch (e) {
emit(MainDoorSensorFailedState(error: e.toString()));
}
});
}
void _revertValueAndEmit(String deviceId, String code, bool oldValue,
Emitter<MainDoorSensorState> emit) {
_updateLocalValue(code, oldValue);
emit(MainDoorSensorDeviceStatusLoaded(deviceStatus));
}
void _updateLocalValue(String code, bool value) {
switch (code) {
case 'doorcontact_state':
deviceStatus = deviceStatus.copyWith(doorContactState: value);
break;
default:
break;
}
}
// Retrieve the current value by code
bool _getValueByCode(String code) {
switch (code) {
case 'doorcontact_state':
return deviceStatus.doorContactState;
default:
return false;
}
}
// Fetch batch status for multiple devices (if needed)
FutureOr<void> _onFetchBatchStatus(MainDoorSensorFetchBatchEvent event,
Emitter<MainDoorSensorState> emit) async {
emit(MainDoorSensorLoadingState());
try {
// final batchStatus =
// await DevicesManagementApi().getBatchDeviceStatus(event.deviceIds);
// Assuming you need to update multiple devices status here
// You might need a list or map of MainDoorSensorStatusModel for batch processing
// emit(MainDoorSensorBatchStatusLoaded(batchStatus));
} catch (e) {
emit(MainDoorSensorBatchFailedState(error: e.toString()));
}
}
// Fetch reports related to the main door sensor
FutureOr<void> _fetchReports(MainDoorSensorReportsEvent event,
Emitter<MainDoorSensorState> emit) async {
emit(MainDoorSensorLoadingState());
try {
final reports = await DevicesManagementApi.getDeviceReports(
event.deviceId, event.code);
emit(MainDoorSensorReportLoaded(reports));
} catch (e) {
emit(MainDoorSensorFailedState(error: e.toString()));
}
}
@override
Future<void> close() {
_timer?.cancel();
return super.close();
}
}

View File

@ -0,0 +1,55 @@
import 'package:equatable/equatable.dart';
class MainDoorSensorEvent extends Equatable {
@override
List<Object?> get props => [];
}
class MainDoorSensorFetchDeviceEvent extends MainDoorSensorEvent {
final String deviceId;
MainDoorSensorFetchDeviceEvent(this.deviceId);
@override
List<Object> get props => [deviceId];
}
class MainDoorSensorFetchBatchEvent extends MainDoorSensorEvent {
final String deviceId;
MainDoorSensorFetchBatchEvent(this.deviceId);
@override
List<Object> get props => [deviceId];
}
class MainDoorSensorControl extends MainDoorSensorEvent {
final String deviceId;
final String code;
final bool value;
MainDoorSensorControl(
{required this.deviceId, required this.code, required this.value});
@override
List<Object> get props => [deviceId, code, value];
}
class MainDoorSensorBatchControl extends MainDoorSensorEvent {
final List<String> deviceId;
final String code;
final bool value;
MainDoorSensorBatchControl(
{required this.deviceId, required this.code, required this.value});
@override
List<Object> get props => [deviceId, code, value];
}
class MainDoorSensorReportsEvent extends MainDoorSensorEvent {
final String deviceId;
final String code;
MainDoorSensorReportsEvent({required this.deviceId, required this.code});
}

View File

@ -0,0 +1,68 @@
import 'package:equatable/equatable.dart';
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_reports.dart';
import 'package:syncrow_web/pages/device_managment/main_door_sensor/models/main_door_status_model.dart';
class MainDoorSensorState extends Equatable {
@override
List<Object?> get props => [];
}
class MainDoorSensorInitial extends MainDoorSensorState {}
class MainDoorSensorLoadingState extends MainDoorSensorState {}
class MainDoorSensorDeviceStatusLoaded extends MainDoorSensorState {
final MainDoorSensorStatusModel status;
MainDoorSensorDeviceStatusLoaded(this.status);
@override
List<Object?> get props => [status];
}
class MainDoorSensorFailedState extends MainDoorSensorState {
final String error;
MainDoorSensorFailedState({required this.error});
@override
List<Object?> get props => [error];
}
class MainDoorSensorBatchFailedState extends MainDoorSensorState {
final String error;
MainDoorSensorBatchFailedState({required this.error});
@override
List<Object?> get props => [error];
}
class MainDoorSensorBatchStatusLoaded extends MainDoorSensorState {
final List<MainDoorSensorStatusModel> status;
MainDoorSensorBatchStatusLoaded(this.status);
@override
List<Object?> get props => [status];
}
class MainDoorSensorReportLoaded extends MainDoorSensorState {
final DeviceReport deviceReport;
MainDoorSensorReportLoaded(this.deviceReport);
@override
List<Object?> get props => [deviceReport];
}
class MainDoorSensorReportsLoadingState extends MainDoorSensorState {}
class MainDoorSensorReportsFailedState extends MainDoorSensorState {
final String error;
MainDoorSensorReportsFailedState({required this.error});
@override
List<Object?> get props => [error];
}

View File

@ -0,0 +1,47 @@
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
class MainDoorSensorStatusModel {
final String uuid;
final bool doorContactState;
final int batteryPercentage;
MainDoorSensorStatusModel({
required this.uuid,
required this.doorContactState,
required this.batteryPercentage,
});
factory MainDoorSensorStatusModel.fromJson(String id, List<Status> jsonList) {
late bool doorContactState = false;
late int batteryPercentage = 0;
for (var status in jsonList) {
switch (status.code) {
case 'doorcontact_state':
doorContactState = status.value ?? false;
break;
case 'battery_percentage':
batteryPercentage = status.value ?? 0;
break;
}
}
return MainDoorSensorStatusModel(
uuid: id,
doorContactState: doorContactState,
batteryPercentage: batteryPercentage,
);
}
MainDoorSensorStatusModel copyWith({
String? uuid,
bool? doorContactState,
int? batteryPercentage,
}) {
return MainDoorSensorStatusModel(
uuid: uuid ?? this.uuid,
doorContactState: doorContactState ?? this.doorContactState,
batteryPercentage: batteryPercentage ?? this.batteryPercentage,
);
}
}

View File

@ -0,0 +1,148 @@
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/models/devices_model.dart';
import 'package:syncrow_web/pages/device_managment/main_door_sensor/bloc/main_door_sensor_bloc.dart';
import 'package:syncrow_web/pages/device_managment/main_door_sensor/bloc/main_door_sensor_event.dart';
import 'package:syncrow_web/pages/device_managment/main_door_sensor/bloc/main_door_sensor_state.dart';
import 'package:syncrow_web/pages/device_managment/main_door_sensor/models/main_door_status_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';
import 'package:syncrow_web/utils/extension/build_context_x.dart';
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
class MainDoorSensorControlView extends StatelessWidget
with HelperResponsiveLayout {
const MainDoorSensorControlView({super.key, required this.device});
final AllDevicesModel device;
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => MainDoorSensorBloc()
..add(MainDoorSensorFetchDeviceEvent(device.uuid!)),
child: BlocBuilder<MainDoorSensorBloc, MainDoorSensorState>(
builder: (context, state) {
if (state is MainDoorSensorLoadingState) {
return const Center(child: CircularProgressIndicator());
} else if (state is MainDoorSensorDeviceStatusLoaded) {
return _buildStatusControls(context, state.status);
} else if (state is MainDoorSensorFailedState ||
state is MainDoorSensorBatchFailedState) {
return const Center(child: Text('Error fetching status'));
} else {
return const Center(child: CircularProgressIndicator());
}
},
));
}
Widget _buildStatusControls(
BuildContext context, MainDoorSensorStatusModel status) {
final isExtraLarge = isExtraLargeScreenSize(context);
final isLarge = isLargeScreenSize(context);
final isMedium = isMediumScreenSize(context);
return GridView(
padding: const EdgeInsets.symmetric(horizontal: 50),
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: isLarge || isExtraLarge
? 3
: isMedium
? 2
: 1,
mainAxisExtent: 140,
crossAxisSpacing: 12,
mainAxisSpacing: 12,
),
children: [
IconNameStatusContainer(
name: 'Open',
icon: Assets.mainDoor,
onTap: () {},
status: status.doorContactState,
textColor: ColorsManager.red,
paddingAmount: 8,
),
IconNameStatusContainer(
name: 'Open/Close\n Record',
icon: Assets.mainDoorReports,
onTap: () {},
status: false,
textColor: ColorsManager.blackColor,
),
IconNameStatusContainer(
name: 'Notifications\n Settings',
icon: Assets.mainDoorNotifi,
onTap: () {},
status: false,
textColor: ColorsManager.blackColor,
),
],
);
}
}
class IconNameStatusContainer extends StatelessWidget {
const IconNameStatusContainer({
super.key,
required this.name,
required this.icon,
required this.onTap,
required this.status,
required this.textColor,
this.paddingAmount = 12,
});
final String name;
final String icon;
final GestureTapCallback onTap;
final bool status;
final Color textColor;
final double? paddingAmount;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
child: DeviceControlsContainer(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: 60,
height: 60,
decoration: const BoxDecoration(
shape: BoxShape.circle,
color: ColorsManager.whiteColors,
),
margin: const EdgeInsets.symmetric(horizontal: 4),
padding: EdgeInsets.all(paddingAmount ?? 12),
child: ClipOval(
child: SvgPicture.asset(
icon,
fit: BoxFit.fill,
),
),
),
const Spacer(),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 6),
child: Text(
name,
textAlign: TextAlign.start,
style: context.textTheme.titleMedium!.copyWith(
fontWeight: FontWeight.w400,
color: textColor,
),
),
),
],
),
),
);
}
}

View File

@ -148,4 +148,10 @@ class Assets {
static const String firmware = 'assets/icons/firmware.svg'; static const String firmware = 'assets/icons/firmware.svg';
//assets/images/scheduling.svg //assets/images/scheduling.svg
static const String scheduling = 'assets/images/scheduling.svg'; static const String scheduling = 'assets/images/scheduling.svg';
//assets/icons/main_door_notifi.svg
static const String mainDoorNotifi = 'assets/icons/main_door_notifi.svg';
//assets/icons/main_door_reports.svg
static const String mainDoorReports = 'assets/icons/main_door_reports.svg';
//assets/icons/main_door.svg
static const String mainDoor = 'assets/icons/main_door.svg';
} }