mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
Compare commits
43 Commits
fix-remove
...
fix-timer-
Author | SHA1 | Date | |
---|---|---|---|
db84a9aa5e | |||
140f4ff5e2 | |||
cbaeecc968 | |||
2a95720cb0 | |||
4fae2d6be0 | |||
5b84076572 | |||
9bf37243a6 | |||
acad0e8c9c | |||
79f5ef7871 | |||
6493f02bcc | |||
c7c8898763 | |||
62ee9a72d6 | |||
55695ca5db | |||
c2f5a8df10 | |||
cd9821679e | |||
bfd3d4542e | |||
35a99ccda7 | |||
978934399e | |||
bc32fe7941 | |||
cb6d50d367 | |||
97eb1c152b | |||
c23176706f | |||
387ef99728 | |||
694a5a7dda | |||
c90b9a1912 | |||
7860292276 | |||
550acc4953 | |||
3d5825adca | |||
9c97e2879a | |||
fda96025e9 | |||
92aa574944 | |||
774f21a55b | |||
9b69ec31e9 | |||
a242377ea6 | |||
3a0c8edf86 | |||
970f7ed16f | |||
006bd4c8ae | |||
b6752683fd | |||
b0846b2fef | |||
8a244dcd23 | |||
9d4395e204 | |||
46f318734a | |||
7accf1d4c8 |
21
assets/icons/active_bell.svg
Normal file
21
assets/icons/active_bell.svg
Normal file
@ -0,0 +1,21 @@
|
||||
<svg width="23" height="23" viewBox="0 0 23 23" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g clip-path="url(#clip0_7572_5102)">
|
||||
<path d="M11.255 22.5148H11.2389C9.82071 22.5148 8.66699 21.361 8.66699 19.9429V19.3419C8.66699 18.9913 8.95123 18.707 9.30183 18.707H13.1921C13.5427 18.707 13.8269 18.9913 13.8269 19.3419V19.9429C13.8269 21.3611 12.6731 22.5148 11.255 22.5148Z" fill="#FFA81C"/>
|
||||
<path d="M13.1912 18.707H11.2461V22.5148H11.2542C12.6723 22.5148 13.826 21.361 13.826 19.9429V19.3419C13.826 18.9912 13.5418 18.707 13.1912 18.707Z" fill="#FF9300"/>
|
||||
<path d="M12.5157 4.81334H9.97762C9.62701 4.81334 9.34277 4.5291 9.34277 4.1785V2.74955C9.34277 1.69974 10.1968 0.845703 11.2466 0.845703C12.2964 0.845703 13.1505 1.69978 13.1505 2.74955V4.1785C13.1505 4.5291 12.8663 4.81334 12.5157 4.81334Z" fill="#FFA81C"/>
|
||||
<path d="M12.5151 4.81334C12.8657 4.81334 13.1499 4.5291 13.1499 4.1785V2.74955C13.1499 1.69974 12.2959 0.845703 11.2461 0.845703V4.81334H12.5151Z" fill="#FF9300"/>
|
||||
<path d="M17.9733 19.9777H4.51899C3.96952 19.9777 3.52246 19.5306 3.52246 18.9811V18.0735C3.52246 17.0793 3.88851 16.1245 4.55319 15.3852C5.00799 14.8792 5.25846 14.226 5.25846 13.5457V9.43293C5.25846 6.13133 7.94448 3.44531 11.2461 3.44531C14.5477 3.44531 17.2337 6.13133 17.2337 9.43293V13.5457C17.2337 14.226 17.4842 14.8792 17.939 15.3851C18.6037 16.1245 18.9697 17.0792 18.9697 18.0734V18.9811C18.9698 19.5306 18.5228 19.9777 17.9733 19.9777Z" fill="#FFCF2C"/>
|
||||
<path d="M17.9732 19.9776C18.5227 19.9776 18.9698 19.5306 18.9698 18.9811V18.0734C18.9698 17.0792 18.6037 16.1245 17.939 15.3851C17.4842 14.8792 17.2337 14.226 17.2337 13.5457V9.43293C17.2337 6.13133 14.5477 3.44531 11.2461 3.44531V19.9776H17.9732Z" fill="#FFC12E"/>
|
||||
<path d="M3.52246 18.0734V18.9811C3.52246 19.5306 3.96952 19.9776 4.51899 19.9776H17.9732C18.5227 19.9776 18.9698 19.5306 18.9698 18.9811V18.0734C18.9698 17.638 18.8995 17.2102 18.7648 16.8047H3.72747C3.59272 17.2102 3.52246 17.638 3.52246 18.0734Z" fill="#FFF566"/>
|
||||
<path d="M11.2461 16.8047V19.9776H17.9732C18.5227 19.9776 18.9698 19.5306 18.9698 18.9811V18.0734C18.9698 17.638 18.8995 17.2102 18.7647 16.8047H11.2461V16.8047Z" fill="#FFE645"/>
|
||||
<path d="M1.04282 7.85721C0.998428 7.85721 0.953397 7.85255 0.908238 7.84278C0.565508 7.7688 0.347673 7.43097 0.421653 7.08824C0.930035 4.73345 2.22744 2.57028 4.07483 0.997187C4.3418 0.769872 4.74247 0.802079 4.96975 1.06897C5.19706 1.33594 5.16494 1.73657 4.89797 1.96388C3.2616 3.35728 2.11262 5.2723 1.66273 7.35619C1.59852 7.65376 1.33536 7.85721 1.04282 7.85721Z" fill="#FF8B6E"/>
|
||||
<path d="M21.4417 7.85717C21.1491 7.85717 20.886 7.65377 20.8218 7.35619C20.3719 5.2723 19.2229 3.35728 17.5866 1.96393C17.3196 1.73661 17.2875 1.33594 17.5148 1.06901C17.7421 0.80204 18.1427 0.769875 18.4097 0.997233C20.2571 2.57024 21.5545 4.73345 22.0628 7.08825C22.1368 7.43098 21.919 7.7688 21.5763 7.84278C21.5311 7.85247 21.4861 7.85717 21.4417 7.85717Z" fill="#FF674F"/>
|
||||
<path d="M3.48329 8.6005C3.4444 8.6005 3.40495 8.5969 3.36534 8.58945C3.02075 8.5247 2.79394 8.19284 2.85869 7.84829C3.20714 5.99413 4.18429 4.28141 5.61006 3.02565C5.87314 2.79385 6.27431 2.81937 6.50603 3.08245C6.73779 3.34557 6.71231 3.74671 6.44923 3.97842C5.23495 5.04796 4.40293 6.50556 4.1065 8.08276C4.04919 8.38778 3.78268 8.6005 3.48329 8.6005Z" fill="#FF8B6E"/>
|
||||
<path d="M19.0004 8.60042C18.701 8.60042 18.4345 8.38771 18.3772 8.08273C18.0808 6.50557 17.2489 5.04793 16.0346 3.97843C15.7715 3.74667 15.7461 3.34554 15.9778 3.08241C16.2095 2.81934 16.6107 2.7939 16.8738 3.02562C18.2995 4.28138 19.2766 5.99405 19.625 7.84817C19.6898 8.19277 19.4629 8.52458 19.1183 8.58933C19.0788 8.59682 19.0393 8.60042 19.0004 8.60042Z" fill="#FF674F"/>
|
||||
</g>
|
||||
<defs>
|
||||
<clipPath id="clip0_7572_5102">
|
||||
<rect width="21.67" height="21.67" fill="white" transform="translate(0.407227 0.845703)"/>
|
||||
</clipPath>
|
||||
</defs>
|
||||
</svg>
|
After Width: | Height: | Size: 3.8 KiB |
3
assets/icons/gear.svg
Normal file
3
assets/icons/gear.svg
Normal file
@ -0,0 +1,3 @@
|
||||
<svg width="22" height="23" viewBox="0 0 22 23" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M21.412 9.9034L18.9398 9.28324C18.788 8.81496 18.5981 8.35938 18.3703 7.92902C18.7373 7.30886 19.522 6.00531 19.522 6.00531C19.6613 5.75219 19.6233 5.43578 19.4208 5.23324L17.6362 3.43609C17.4338 3.23364 17.1047 3.19563 16.8642 3.3475L14.9404 4.49922C14.4975 4.27141 14.0419 4.08152 13.5862 3.92969L12.9661 1.45754C12.9028 1.17902 12.6496 0.976562 12.3586 0.976562H9.82734C9.53629 0.976562 9.28312 1.17902 9.21989 1.4575C9.21989 1.4575 8.78953 3.18293 8.59973 3.92965C8.10614 4.09418 7.62516 4.29663 7.16957 4.5498L5.16984 3.34746C4.91672 3.19558 4.60031 3.23359 4.39781 3.43605L2.61328 5.23324C2.39817 5.43578 2.36016 5.75219 2.51199 6.00531L3.75234 8.06828C3.5498 8.46063 3.38527 8.86563 3.24609 9.28324L0.773948 9.9034C0.495427 9.96672 0.292969 10.2198 0.292969 10.5109V13.0422C0.292969 13.3332 0.495427 13.5864 0.773906 13.6496L3.24609 14.2698C3.39797 14.7381 3.60051 15.2064 3.82832 15.6494L2.72723 17.4845C2.57535 17.7376 2.61328 18.054 2.82844 18.2692L4.61301 20.0537C4.81547 20.2563 5.13188 20.2942 5.38504 20.1423C5.38504 20.1423 6.62531 19.4082 7.2329 19.0412C7.67578 19.2817 8.13136 19.4715 8.59973 19.6234L9.21989 22.0956C9.28317 22.374 9.53629 22.5765 9.82734 22.5765H12.3586C12.6496 22.5765 12.9028 22.374 12.9661 22.0956L13.5862 19.6234C14.0671 19.4715 14.5354 19.269 14.9911 19.0286C15.6112 19.3955 16.8642 20.1423 16.8642 20.1423C17.1046 20.2942 17.4337 20.2563 17.6362 20.0537L19.4208 18.2692C19.6232 18.054 19.6613 17.7376 19.522 17.4845L18.383 15.5987C18.6108 15.1684 18.788 14.7254 18.9398 14.2698L21.412 13.6496C21.6905 13.5864 21.8929 13.3332 21.8929 13.0422V10.5109C21.893 10.2198 21.6905 9.96672 21.412 9.9034ZM11.093 16.2063C8.65031 16.2063 6.66328 14.2192 6.66328 11.7766C6.66328 9.33391 8.65031 7.34688 11.093 7.34688C13.5356 7.34688 15.5227 9.33391 15.5227 11.7766C15.5227 14.2192 13.5356 16.2063 11.093 16.2063Z" fill="#A1A7B3"/>
|
||||
</svg>
|
After Width: | Height: | Size: 1.9 KiB |
@ -201,20 +201,17 @@ class ForgetPasswordWebPage extends StatelessWidget {
|
||||
!state.isButtonEnabled &&
|
||||
state.remainingTime != 1
|
||||
? null
|
||||
: () {
|
||||
:
|
||||
() {
|
||||
if (forgetBloc
|
||||
.forgetEmailKey.currentState!
|
||||
.validate() ||
|
||||
forgetBloc
|
||||
.forgetRegionKey.currentState!
|
||||
.validate()) {
|
||||
if (forgetBloc
|
||||
.forgetRegionKey.currentState!
|
||||
.validate()) {
|
||||
forgetBloc.add(StartTimerEvent());
|
||||
}
|
||||
.forgetEmailKey
|
||||
.currentState!
|
||||
.validate()) {
|
||||
forgetBloc.add(
|
||||
StartTimerEvent());
|
||||
}
|
||||
},
|
||||
|
||||
child: Text(
|
||||
'Get Code ${state is TimerState && !state.isButtonEnabled && state.remainingTime != 1 ? "(${forgetBloc.formattedTime(state.remainingTime)}) " : ""}',
|
||||
style: TextStyle(
|
||||
|
@ -13,6 +13,7 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
late AcStatusModel deviceStatus;
|
||||
final String deviceId;
|
||||
Timer? _timer;
|
||||
Timer? _countdownTimer;
|
||||
|
||||
AcBloc({required this.deviceId}) : super(AcsInitialState()) {
|
||||
on<AcFetchDeviceStatusEvent>(_onFetchAcStatus);
|
||||
@ -21,7 +22,16 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
on<AcBatchControlEvent>(_onAcBatchControl);
|
||||
on<AcFactoryResetEvent>(_onFactoryReset);
|
||||
on<AcStatusUpdated>(_onAcStatusUpdated);
|
||||
on<OnClose>(_onClose);
|
||||
on<IncreaseTimeEvent>(_handleIncreaseTime);
|
||||
on<DecreaseTimeEvent>(_handleDecreaseTime);
|
||||
on<UpdateTimerEvent>(_handleUpdateTimer);
|
||||
on<ToggleScheduleEvent>(_handleToggleTimer);
|
||||
on<ApiCountdownValueEvent>(_handleApiCountdownValue);
|
||||
}
|
||||
bool timerActive = false;
|
||||
int scheduledHours = 0;
|
||||
int scheduledMinutes = 0;
|
||||
|
||||
FutureOr<void> _onFetchAcStatus(
|
||||
AcFetchDeviceStatusEvent event, Emitter<AcsState> emit) async {
|
||||
@ -30,8 +40,23 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
final status =
|
||||
await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||
deviceStatus = AcStatusModel.fromJson(event.deviceId, status.status);
|
||||
if (deviceStatus.countdown1 != 0) {
|
||||
// Convert API value to minutes
|
||||
final totalMinutes = deviceStatus.countdown1 * 6;
|
||||
scheduledHours = totalMinutes ~/ 60;
|
||||
scheduledMinutes = totalMinutes % 60;
|
||||
timerActive = true;
|
||||
_startCountdownTimer(emit);
|
||||
}
|
||||
|
||||
emit(ACStatusLoaded(
|
||||
status: deviceStatus,
|
||||
scheduledHours: scheduledHours,
|
||||
scheduledMinutes: scheduledMinutes,
|
||||
isTimerActive: timerActive,
|
||||
));
|
||||
|
||||
_listenToChanges(event.deviceId);
|
||||
emit(ACStatusLoaded(deviceStatus));
|
||||
} catch (e) {
|
||||
emit(AcsFailedState(error: e.toString()));
|
||||
}
|
||||
@ -70,31 +95,16 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
|
||||
void _onAcStatusUpdated(AcStatusUpdated event, Emitter<AcsState> emit) {
|
||||
deviceStatus = event.deviceStatus;
|
||||
emit(ACStatusLoaded(deviceStatus));
|
||||
emit(ACStatusLoaded(status: deviceStatus));
|
||||
}
|
||||
|
||||
// Future<void> testFirebaseConnection() async {
|
||||
// // Reference to a test node in your database
|
||||
// final testRef = FirebaseDatabase.instance.ref("test");
|
||||
|
||||
// // Write a test value
|
||||
// await testRef.set("Hello, Firebase!");
|
||||
|
||||
// // Listen for changes on the test node
|
||||
// testRef.onValue.listen((DatabaseEvent event) {
|
||||
// final data = event.snapshot.value;
|
||||
// print("Data from Firebase: $data");
|
||||
// // If you see "Hello, Firebase!" printed in your console, it means the connection works.
|
||||
// });
|
||||
// }
|
||||
|
||||
FutureOr<void> _onAcControl(
|
||||
AcControlEvent event, Emitter<AcsState> emit) async {
|
||||
final oldValue = _getValueByCode(event.code);
|
||||
|
||||
_updateLocalValue(event.code, event.value, emit);
|
||||
|
||||
emit(ACStatusLoaded(deviceStatus));
|
||||
emit(ACStatusLoaded(status: deviceStatus));
|
||||
|
||||
await _runDebounce(
|
||||
isBatch: false,
|
||||
@ -151,7 +161,7 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
void _revertValueAndEmit(
|
||||
String deviceId, String code, dynamic oldValue, Emitter<AcsState> emit) {
|
||||
_updateLocalValue(code, oldValue, emit);
|
||||
emit(ACStatusLoaded(deviceStatus));
|
||||
emit(ACStatusLoaded(status: deviceStatus));
|
||||
}
|
||||
|
||||
void _updateLocalValue(String code, dynamic value, Emitter<AcsState> emit) {
|
||||
@ -184,11 +194,16 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
if (value is bool) {
|
||||
deviceStatus = deviceStatus.copyWith(childLock: value);
|
||||
}
|
||||
|
||||
case 'countdown_time':
|
||||
if (value is int) {
|
||||
deviceStatus = deviceStatus.copyWith(countdown1: value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
emit(ACStatusLoaded(deviceStatus));
|
||||
emit(ACStatusLoaded(status: deviceStatus));
|
||||
}
|
||||
|
||||
dynamic _getValueByCode(String code) {
|
||||
@ -203,6 +218,8 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
return deviceStatus.fanSpeedsString;
|
||||
case 'child_lock':
|
||||
return deviceStatus.childLock;
|
||||
case 'countdown_time':
|
||||
return deviceStatus.countdown1;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@ -216,7 +233,7 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
await DevicesManagementApi().getBatchStatus(event.devicesIds);
|
||||
deviceStatus =
|
||||
AcStatusModel.fromJson(event.devicesIds.first, status.status);
|
||||
emit(ACStatusLoaded(deviceStatus));
|
||||
emit(ACStatusLoaded(status: deviceStatus));
|
||||
} catch (e) {
|
||||
emit(AcsFailedState(error: e.toString()));
|
||||
}
|
||||
@ -228,7 +245,7 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
|
||||
_updateLocalValue(event.code, event.value, emit);
|
||||
|
||||
emit(ACStatusLoaded(deviceStatus));
|
||||
emit(ACStatusLoaded(status: deviceStatus));
|
||||
|
||||
await _runDebounce(
|
||||
isBatch: true,
|
||||
@ -257,4 +274,144 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
emit(AcsFailedState(error: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
void _onClose(OnClose event, Emitter<AcsState> emit) {
|
||||
_countdownTimer?.cancel();
|
||||
_timer?.cancel();
|
||||
}
|
||||
|
||||
void _handleIncreaseTime(IncreaseTimeEvent event, Emitter<AcsState> emit) {
|
||||
if (state is! ACStatusLoaded) return;
|
||||
final currentState = state as ACStatusLoaded;
|
||||
int newHours = scheduledHours;
|
||||
int newMinutes = scheduledMinutes + 30;
|
||||
newHours += newMinutes ~/ 60;
|
||||
newMinutes = newMinutes % 60;
|
||||
if (newHours > 23) {
|
||||
newHours = 23;
|
||||
newMinutes = 59;
|
||||
}
|
||||
scheduledHours = newHours;
|
||||
scheduledMinutes = newMinutes;
|
||||
|
||||
emit(currentState.copyWith(
|
||||
scheduledHours: scheduledHours,
|
||||
scheduledMinutes: scheduledMinutes,
|
||||
));
|
||||
}
|
||||
|
||||
void _handleDecreaseTime(DecreaseTimeEvent event, Emitter<AcsState> emit) {
|
||||
if (state is! ACStatusLoaded) return;
|
||||
final currentState = state as ACStatusLoaded;
|
||||
int totalMinutes = (scheduledHours * 60) + scheduledMinutes;
|
||||
totalMinutes = (totalMinutes - 30).clamp(0, 1440);
|
||||
scheduledHours = totalMinutes ~/ 60;
|
||||
scheduledMinutes = totalMinutes % 60;
|
||||
|
||||
emit(currentState.copyWith(
|
||||
scheduledHours: scheduledHours,
|
||||
scheduledMinutes: scheduledMinutes,
|
||||
));
|
||||
}
|
||||
|
||||
Future<void> _handleToggleTimer(
|
||||
ToggleScheduleEvent event, Emitter<AcsState> emit) async {
|
||||
if (state is! ACStatusLoaded) return;
|
||||
final currentState = state as ACStatusLoaded;
|
||||
|
||||
timerActive = !timerActive;
|
||||
|
||||
if (timerActive) {
|
||||
final totalMinutes = scheduledHours * 60 + scheduledMinutes;
|
||||
if (totalMinutes <= 0) {
|
||||
timerActive = false;
|
||||
emit(currentState.copyWith(isTimerActive: timerActive));
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final scaledValue = totalMinutes ~/ 6;
|
||||
await _runDebounce(
|
||||
isBatch: false,
|
||||
deviceId: deviceId,
|
||||
code: 'countdown_time',
|
||||
value: scaledValue,
|
||||
oldValue: scaledValue,
|
||||
emit: emit,
|
||||
);
|
||||
_startCountdownTimer(emit);
|
||||
emit(currentState.copyWith(isTimerActive: timerActive));
|
||||
} catch (e) {
|
||||
timerActive = false;
|
||||
emit(AcsFailedState(error: e.toString()));
|
||||
}
|
||||
} else {
|
||||
await _runDebounce(
|
||||
isBatch: false,
|
||||
deviceId: deviceId,
|
||||
code: 'countdown_time',
|
||||
value: 0,
|
||||
oldValue: 0,
|
||||
emit: emit,
|
||||
);
|
||||
_countdownTimer?.cancel();
|
||||
scheduledHours = 0;
|
||||
scheduledMinutes = 0;
|
||||
emit(currentState.copyWith(
|
||||
isTimerActive: timerActive,
|
||||
scheduledHours: 0,
|
||||
scheduledMinutes: 0,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
void _startCountdownTimer(Emitter<AcsState> emit) {
|
||||
_countdownTimer?.cancel();
|
||||
int totalSeconds = (scheduledHours * 3600) + (scheduledMinutes * 60);
|
||||
|
||||
_countdownTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||
if (totalSeconds > 0) {
|
||||
totalSeconds--;
|
||||
scheduledHours = totalSeconds ~/ 3600;
|
||||
scheduledMinutes = (totalSeconds % 3600) ~/ 60;
|
||||
add(UpdateTimerEvent());
|
||||
} else {
|
||||
_countdownTimer?.cancel();
|
||||
timerActive = false;
|
||||
scheduledHours = 0;
|
||||
scheduledMinutes = 0;
|
||||
add(TimerCompletedEvent());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _handleUpdateTimer(UpdateTimerEvent event, Emitter<AcsState> emit) {
|
||||
if (state is ACStatusLoaded) {
|
||||
final currentState = state as ACStatusLoaded;
|
||||
emit(currentState.copyWith(
|
||||
scheduledHours: scheduledHours,
|
||||
scheduledMinutes: scheduledMinutes,
|
||||
isTimerActive: timerActive,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
void _handleApiCountdownValue(
|
||||
ApiCountdownValueEvent event, Emitter<AcsState> emit) {
|
||||
if (state is ACStatusLoaded) {
|
||||
final totalMinutes = event.apiValue * 6;
|
||||
final scheduledHours = totalMinutes ~/ 60;
|
||||
scheduledMinutes = totalMinutes % 60;
|
||||
_startCountdownTimer(
|
||||
emit,
|
||||
);
|
||||
add(UpdateTimerEvent());
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() {
|
||||
add(OnClose());
|
||||
return super.close();
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ sealed class AcsEvent extends Equatable {
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class AcUpdated extends AcsEvent {}
|
||||
|
||||
class AcFetchDeviceStatusEvent extends AcsEvent {
|
||||
@ -18,10 +19,12 @@ class AcFetchDeviceStatusEvent extends AcsEvent {
|
||||
@override
|
||||
List<Object> get props => [deviceId];
|
||||
}
|
||||
|
||||
class AcStatusUpdated extends AcsEvent {
|
||||
final AcStatusModel deviceStatus;
|
||||
AcStatusUpdated(this.deviceStatus);
|
||||
}
|
||||
|
||||
class AcFetchBatchStatusEvent extends AcsEvent {
|
||||
final List<String> devicesIds;
|
||||
|
||||
@ -73,3 +76,30 @@ class AcFactoryResetEvent extends AcsEvent {
|
||||
@override
|
||||
List<Object> get props => [deviceId, factoryResetModel];
|
||||
}
|
||||
|
||||
|
||||
|
||||
class OnClose extends AcsEvent {}
|
||||
|
||||
class IncreaseTimeEvent extends AcsEvent {
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class DecreaseTimeEvent extends AcsEvent {
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class ToggleScheduleEvent extends AcsEvent {}
|
||||
|
||||
class TimerCompletedEvent extends AcsEvent {}
|
||||
|
||||
class UpdateTimerEvent extends AcsEvent {
|
||||
}
|
||||
|
||||
class ApiCountdownValueEvent extends AcsEvent {
|
||||
final int apiValue;
|
||||
|
||||
const ApiCountdownValueEvent(this.apiValue);
|
||||
}
|
||||
|
@ -2,8 +2,9 @@ import 'package:equatable/equatable.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/model/ac_model.dart';
|
||||
|
||||
abstract class AcsState extends Equatable {
|
||||
const AcsState();
|
||||
final bool isTimerActive;
|
||||
|
||||
const AcsState({this.isTimerActive = false});
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
@ -15,8 +16,30 @@ class AcsLoadingState extends AcsState {}
|
||||
class ACStatusLoaded extends AcsState {
|
||||
final AcStatusModel status;
|
||||
final DateTime timestamp;
|
||||
final int scheduledHours;
|
||||
final int scheduledMinutes;
|
||||
final bool isTimerActive;
|
||||
|
||||
ACStatusLoaded(this.status) : timestamp = DateTime.now();
|
||||
ACStatusLoaded({
|
||||
required this.status,
|
||||
this.scheduledHours = 0,
|
||||
this.scheduledMinutes = 0,
|
||||
this.isTimerActive = false,
|
||||
}) : timestamp = DateTime.now();
|
||||
ACStatusLoaded copyWith({
|
||||
AcStatusModel? status,
|
||||
int? scheduledHours,
|
||||
int? scheduledMinutes,
|
||||
bool? isTimerActive,
|
||||
int? remainingTime,
|
||||
}) {
|
||||
return ACStatusLoaded(
|
||||
status: status ?? this.status,
|
||||
scheduledHours: scheduledHours ?? this.scheduledHours,
|
||||
scheduledMinutes: scheduledMinutes ?? this.scheduledMinutes,
|
||||
isTimerActive: isTimerActive ?? this.isTimerActive,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object> get props => [status, timestamp];
|
||||
@ -40,3 +63,14 @@ class AcsFailedState extends AcsState {
|
||||
@override
|
||||
List<Object> get props => [error];
|
||||
}
|
||||
|
||||
class TimerRunInProgress extends AcsState {
|
||||
final int remainingTime;
|
||||
|
||||
const TimerRunInProgress(this.remainingTime);
|
||||
|
||||
@override
|
||||
List<Object> get props => [remainingTime];
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,6 +11,7 @@ class AcStatusModel {
|
||||
final bool childLock;
|
||||
final TempModes acMode;
|
||||
final FanSpeeds acFanSpeed;
|
||||
final int countdown1;
|
||||
|
||||
AcStatusModel({
|
||||
required this.uuid,
|
||||
@ -18,6 +19,7 @@ class AcStatusModel {
|
||||
required this.modeString,
|
||||
required this.tempSet,
|
||||
required this.currentTemp,
|
||||
required this.countdown1,
|
||||
required this.fanSpeedsString,
|
||||
required this.childLock,
|
||||
}) : acMode = getACMode(modeString),
|
||||
@ -30,6 +32,7 @@ class AcStatusModel {
|
||||
late int currentTemp;
|
||||
late String fanSpeeds;
|
||||
late bool childLock;
|
||||
late int _countdown1 = 0;
|
||||
|
||||
for (var status in jsonList) {
|
||||
switch (status.code) {
|
||||
@ -51,6 +54,9 @@ class AcStatusModel {
|
||||
case 'child_lock':
|
||||
childLock = status.value ?? false;
|
||||
break;
|
||||
case 'countdown_time':
|
||||
_countdown1 = status.value ?? 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,6 +68,7 @@ class AcStatusModel {
|
||||
currentTemp: currentTemp,
|
||||
fanSpeedsString: fanSpeeds,
|
||||
childLock: childLock,
|
||||
countdown1: _countdown1,
|
||||
);
|
||||
}
|
||||
|
||||
@ -73,6 +80,7 @@ class AcStatusModel {
|
||||
int? currentTemp,
|
||||
String? fanSpeedsString,
|
||||
bool? childLock,
|
||||
int? countdown1,
|
||||
}) {
|
||||
return AcStatusModel(
|
||||
uuid: uuid ?? this.uuid,
|
||||
@ -82,6 +90,7 @@ class AcStatusModel {
|
||||
currentTemp: currentTemp ?? this.currentTemp,
|
||||
fanSpeedsString: fanSpeedsString ?? this.fanSpeedsString,
|
||||
childLock: childLock ?? this.childLock,
|
||||
countdown1: countdown1 ?? this.countdown1,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -10,11 +10,10 @@ import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_mo
|
||||
import 'package:syncrow_web/pages/device_managment/shared/toggle_widget.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 AcDeviceControlsView extends StatelessWidget with HelperResponsiveLayout {
|
||||
const AcDeviceControlsView({super.key, required this.device});
|
||||
const AcDeviceControlsView({super.key, required this.device});
|
||||
|
||||
final AllDevicesModel device;
|
||||
|
||||
@ -23,11 +22,13 @@ class AcDeviceControlsView extends StatelessWidget with HelperResponsiveLayout {
|
||||
final isExtraLarge = isExtraLargeScreenSize(context);
|
||||
final isLarge = isLargeScreenSize(context);
|
||||
final isMedium = isMediumScreenSize(context);
|
||||
|
||||
return BlocProvider(
|
||||
create: (context) => AcBloc(deviceId: device.uuid!)
|
||||
..add(AcFetchDeviceStatusEvent(device.uuid!)),
|
||||
child: BlocBuilder<AcBloc, AcsState>(
|
||||
builder: (context, state) {
|
||||
final acBloc = BlocProvider.of<AcBloc>(context);
|
||||
if (state is ACStatusLoaded) {
|
||||
return GridView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 50),
|
||||
@ -78,56 +79,101 @@ class AcDeviceControlsView extends StatelessWidget with HelperResponsiveLayout {
|
||||
),
|
||||
ToggleWidget(
|
||||
label: '',
|
||||
labelWidget: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
labelWidget: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
IconButton(
|
||||
padding: const EdgeInsets.all(0),
|
||||
onPressed: () {},
|
||||
icon: const Icon(
|
||||
Icons.remove,
|
||||
size: 28,
|
||||
color: ColorsManager.greyColor,
|
||||
Container(
|
||||
width: MediaQuery.of(context).size.width,
|
||||
decoration: const ShapeDecoration(
|
||||
color: ColorsManager.primaryColor,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(30)),
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'06',
|
||||
style: context.textTheme.titleLarge!.copyWith(
|
||||
color: ColorsManager.dialogBlueTitle,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'h',
|
||||
style: context.textTheme.bodySmall!
|
||||
.copyWith(color: ColorsManager.blackColor),
|
||||
),
|
||||
Text(
|
||||
'30',
|
||||
style: context.textTheme.titleLarge!.copyWith(
|
||||
color: ColorsManager.dialogBlueTitle,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Text('m',
|
||||
style: context.textTheme.bodySmall!
|
||||
.copyWith(color: ColorsManager.blackColor)),
|
||||
IconButton(
|
||||
padding: const EdgeInsets.all(0),
|
||||
onPressed: () {},
|
||||
icon: const Icon(
|
||||
Icons.add,
|
||||
size: 28,
|
||||
color: ColorsManager.greyColor,
|
||||
Center(
|
||||
child: SizedBox(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
if (acBloc.timerActive == false) {
|
||||
context
|
||||
.read<AcBloc>()
|
||||
.add(DecreaseTimeEvent());
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.remove,
|
||||
color: ColorsManager.greyColor),
|
||||
),
|
||||
Text(
|
||||
acBloc.scheduledHours
|
||||
.toString()
|
||||
.padLeft(2, '0'),
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.titleLarge!
|
||||
.copyWith(
|
||||
color: ColorsManager.dialogBlueTitle,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'h',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall!
|
||||
.copyWith(
|
||||
color: ColorsManager.blackColor,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
acBloc.scheduledMinutes
|
||||
.toString()
|
||||
.padLeft(2, '0'),
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.titleLarge!
|
||||
.copyWith(
|
||||
color: ColorsManager.dialogBlueTitle,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'm',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall!
|
||||
.copyWith(
|
||||
color: ColorsManager.blackColor,
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
if (acBloc.timerActive == false) {
|
||||
context
|
||||
.read<AcBloc>()
|
||||
.add(IncreaseTimeEvent());
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.add,
|
||||
color: ColorsManager.greyColor),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
value: false,
|
||||
value: acBloc.timerActive,
|
||||
code: 'ac_schedule',
|
||||
deviceId: device.uuid!,
|
||||
icon: Assets.acSchedule,
|
||||
onChange: (value) {},
|
||||
onChange: (value) {
|
||||
context.read<AcBloc>().add(ToggleScheduleEvent());
|
||||
},
|
||||
),
|
||||
ToggleWidget(
|
||||
deviceId: device.uuid!,
|
||||
|
@ -8,6 +8,7 @@ import 'package:syncrow_web/pages/routines/models/device_functions.dart';
|
||||
import 'package:syncrow_web/pages/routines/models/gang_switches/one_gang_switch/one_gang_switch.dart';
|
||||
import 'package:syncrow_web/pages/routines/models/gang_switches/three_gang_switch/three_gang_switch.dart';
|
||||
import 'package:syncrow_web/pages/routines/models/gang_switches/two_gang_switch/two_gang_switch.dart';
|
||||
import 'package:syncrow_web/pages/routines/models/gateway.dart';
|
||||
import 'package:syncrow_web/pages/routines/models/wps/wps_functions.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:syncrow_web/utils/enum/device_types.dart';
|
||||
@ -318,6 +319,24 @@ SOS
|
||||
deviceId: uuid ?? '', deviceName: name ?? '', type: 'THEN'),
|
||||
|
||||
];
|
||||
case 'GW':
|
||||
return [
|
||||
GatewaySwitchAlarmSound(
|
||||
deviceId: uuid ?? '',
|
||||
deviceName: name ?? '',
|
||||
type: 'BOTH',
|
||||
),
|
||||
GatewayMasterState(
|
||||
deviceId: uuid ?? '',
|
||||
deviceName: name ?? '',
|
||||
type: 'BOTH',
|
||||
),
|
||||
GatewayFactoryReset(
|
||||
deviceId: uuid ?? '',
|
||||
deviceName: name ?? '',
|
||||
type: 'BOTH',
|
||||
),
|
||||
];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
|
49
lib/pages/device_managment/gateway/model/gateway_model.dart
Normal file
49
lib/pages/device_managment/gateway/model/gateway_model.dart
Normal file
@ -0,0 +1,49 @@
|
||||
class GatewayModel {
|
||||
final String uuid;
|
||||
final bool switchAlarmSound;
|
||||
final String masterState;
|
||||
final bool factoryReset;
|
||||
final String alarmActive;
|
||||
|
||||
GatewayModel({
|
||||
required this.uuid,
|
||||
required this.switchAlarmSound,
|
||||
required this.masterState,
|
||||
required this.factoryReset,
|
||||
required this.alarmActive,
|
||||
});
|
||||
|
||||
factory GatewayModel.fromJson(Map<String, dynamic> json) {
|
||||
final status = json['status'] as List<dynamic>? ?? <dynamic>[];
|
||||
|
||||
bool? switchAlarmSound;
|
||||
String? masterState;
|
||||
bool? factoryReset;
|
||||
String? alarmActive;
|
||||
|
||||
for (final item in status) {
|
||||
switch (item['code']) {
|
||||
case 'switch_alarm_sound':
|
||||
switchAlarmSound = item['value'] as bool;
|
||||
break;
|
||||
case 'master_state':
|
||||
masterState = item['value'] as String;
|
||||
break;
|
||||
case 'factory_reset':
|
||||
factoryReset = item['value'] as bool;
|
||||
break;
|
||||
case 'alarm_active':
|
||||
alarmActive = item['value'] as String;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return GatewayModel(
|
||||
uuid: json['uuid'] as String? ?? '',
|
||||
switchAlarmSound: switchAlarmSound ?? false,
|
||||
masterState: masterState ?? '',
|
||||
factoryReset: factoryReset ?? false,
|
||||
alarmActive: alarmActive ?? '',
|
||||
);
|
||||
}
|
||||
}
|
@ -62,9 +62,6 @@ class ToggleWidget extends StatelessWidget {
|
||||
)),
|
||||
if (showToggle)
|
||||
Container(
|
||||
height: 20,
|
||||
width: 35,
|
||||
padding: const EdgeInsets.only(right: 16, top: 10),
|
||||
child: CupertinoSwitch(
|
||||
value: value,
|
||||
activeColor: ColorsManager.dialogBlueTitle,
|
||||
|
@ -13,7 +13,8 @@ import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_la
|
||||
|
||||
import '../models/sos_status_model.dart';
|
||||
|
||||
class SosDeviceControlsView extends StatelessWidget with HelperResponsiveLayout {
|
||||
class SosDeviceControlsView extends StatelessWidget
|
||||
with HelperResponsiveLayout {
|
||||
const SosDeviceControlsView({
|
||||
super.key,
|
||||
required this.device,
|
||||
@ -24,7 +25,8 @@ class SosDeviceControlsView extends StatelessWidget with HelperResponsiveLayout
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => SosDeviceBloc()..add(GetDeviceStatus(device.uuid!)),
|
||||
create: (context) =>
|
||||
SosDeviceBloc()..add(GetDeviceStatus(device.uuid!)),
|
||||
child: BlocBuilder<SosDeviceBloc, SosDeviceState>(
|
||||
builder: (context, state) {
|
||||
if (state is SosDeviceLoadingState) {
|
||||
@ -63,7 +65,8 @@ class SosDeviceControlsView extends StatelessWidget with HelperResponsiveLayout
|
||||
));
|
||||
}
|
||||
|
||||
Widget _buildStatusControls(BuildContext context, SosStatusModel deviceStatus) {
|
||||
Widget _buildStatusControls(
|
||||
BuildContext context, SosStatusModel deviceStatus) {
|
||||
final isExtraLarge = isExtraLargeScreenSize(context);
|
||||
final isLarge = isLargeScreenSize(context);
|
||||
final isMedium = isMediumScreenSize(context);
|
||||
@ -85,7 +88,7 @@ class SosDeviceControlsView extends StatelessWidget with HelperResponsiveLayout
|
||||
IconNameStatusContainer(
|
||||
isFullIcon: false,
|
||||
name: deviceStatus.sosStatus == 'sos' ? 'SOS' : 'Normal',
|
||||
icon: deviceStatus.sosStatus == 'sos' ? Assets.sos : Assets.sosNormal,
|
||||
icon: deviceStatus.sosStatus == 'sos' ? Assets.sosNormal : Assets.sos,
|
||||
onTap: () {},
|
||||
status: false,
|
||||
textColor: ColorsManager.blackColor,
|
||||
|
@ -1,11 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
||||
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/ac_dialog.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/gateway/gateway_helper.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/one_gang_switch_dialog.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/three_gang_switch_dialog.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/two_gang_switch_dialog.dart';
|
||||
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/wall_sensor/wall_presence_sensor.dart';
|
||||
|
||||
class DeviceDialogHelper {
|
||||
@ -49,7 +50,6 @@ class DeviceDialogHelper {
|
||||
final deviceSelectedFunctions =
|
||||
routineBloc.state.selectedFunctions[data['uniqueCustomId']] ?? [];
|
||||
|
||||
|
||||
switch (productType) {
|
||||
case 'AC':
|
||||
return ACHelper.showACFunctionsDialog(
|
||||
@ -98,6 +98,15 @@ class DeviceDialogHelper {
|
||||
deviceSelectedFunctions: deviceSelectedFunctions,
|
||||
uniqueCustomId: data['uniqueCustomId'],
|
||||
removeComparetors: removeComparetors);
|
||||
case 'GW':
|
||||
return GatewayHelper.showGatewayFunctionsDialog(
|
||||
context: context,
|
||||
functions: functions,
|
||||
uniqueCustomId: data['uniqueCustomId'],
|
||||
deviceSelectedFunctions: deviceSelectedFunctions,
|
||||
device: data['device'],
|
||||
);
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
111
lib/pages/routines/models/gateway.dart
Normal file
111
lib/pages/routines/models/gateway.dart
Normal file
@ -0,0 +1,111 @@
|
||||
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
|
||||
class GatewayOperationalValue {
|
||||
final String icon;
|
||||
final String description;
|
||||
final dynamic value;
|
||||
|
||||
GatewayOperationalValue({
|
||||
required this.icon,
|
||||
required this.description,
|
||||
required this.value,
|
||||
});
|
||||
}
|
||||
|
||||
abstract class GatewayFunctions extends DeviceFunction<GatewayOperationalValue> {
|
||||
final String type;
|
||||
|
||||
GatewayFunctions({
|
||||
required super.deviceId,
|
||||
required super.deviceName,
|
||||
required super.code,
|
||||
required super.operationName,
|
||||
required super.icon,
|
||||
required this.type,
|
||||
});
|
||||
|
||||
List<GatewayOperationalValue> getOperationalValues();
|
||||
}
|
||||
|
||||
final class GatewaySwitchAlarmSound extends GatewayFunctions {
|
||||
GatewaySwitchAlarmSound({
|
||||
required super.deviceId,
|
||||
required super.deviceName,
|
||||
required super.type,
|
||||
}) : super(
|
||||
code: 'switch_alarm_sound',
|
||||
operationName: 'Switch Alarm Sound',
|
||||
icon: Assets.activeBell,
|
||||
);
|
||||
|
||||
@override
|
||||
List<GatewayOperationalValue> getOperationalValues() => [
|
||||
GatewayOperationalValue(
|
||||
icon: Assets.assetsAcPower,
|
||||
description: "ON",
|
||||
value: true,
|
||||
),
|
||||
GatewayOperationalValue(
|
||||
icon: Assets.assetsAcPowerOFF,
|
||||
description: "OFF",
|
||||
value: false,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
final class GatewayMasterState extends GatewayFunctions {
|
||||
GatewayMasterState({
|
||||
required super.deviceId,
|
||||
required super.deviceName,
|
||||
required super.type,
|
||||
}) : super(
|
||||
code: 'master_state',
|
||||
operationName: 'Master State',
|
||||
icon: Assets.gear,
|
||||
);
|
||||
|
||||
@override
|
||||
List<GatewayOperationalValue> getOperationalValues() {
|
||||
return [
|
||||
GatewayOperationalValue(
|
||||
icon: Assets.assetsAcPower,
|
||||
description: "Normal",
|
||||
value: 'normal',
|
||||
),
|
||||
GatewayOperationalValue(
|
||||
icon: Assets.assetsAcPowerOFF,
|
||||
description: "Alarm",
|
||||
value: 'alarm',
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
final class GatewayFactoryReset extends GatewayFunctions {
|
||||
GatewayFactoryReset({
|
||||
required super.deviceId,
|
||||
required super.deviceName,
|
||||
required super.type,
|
||||
}) : super(
|
||||
code: 'factory_reset',
|
||||
operationName: 'Factory Reset',
|
||||
icon: Assets.factoryReset,
|
||||
);
|
||||
|
||||
@override
|
||||
List<GatewayOperationalValue> getOperationalValues() {
|
||||
return [
|
||||
GatewayOperationalValue(
|
||||
icon: Assets.assetsAcPower,
|
||||
description: "ON",
|
||||
value: true,
|
||||
),
|
||||
GatewayOperationalValue(
|
||||
icon: Assets.assetsAcPowerOFF,
|
||||
description: "OFF",
|
||||
value: false,
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
@ -72,6 +72,7 @@ class IfContainer extends StatelessWidget {
|
||||
'2G',
|
||||
'3G',
|
||||
'WPS'
|
||||
'GW',
|
||||
].contains(
|
||||
state.ifItems[index]['productType'])) {
|
||||
context.read<RoutineBloc>().add(
|
||||
@ -129,7 +130,7 @@ class IfContainer extends StatelessWidget {
|
||||
context
|
||||
.read<RoutineBloc>()
|
||||
.add(AddToIfContainer(mutableData, false));
|
||||
} else if (!['AC', '1G', '2G', '3G', 'WPS']
|
||||
} else if (!['AC', '1G', '2G', '3G', 'WPS', 'GW']
|
||||
.contains(mutableData['productType'])) {
|
||||
context
|
||||
.read<RoutineBloc>()
|
||||
|
@ -183,7 +183,7 @@ class _FetchRoutineScenesState extends State<FetchRoutineScenesAutomation>
|
||||
state.automations[index].id,
|
||||
cardType: 'automations',
|
||||
spaceName:
|
||||
state.scenes[index].spaceName,
|
||||
state.automations[index].spaceName,
|
||||
onTap: () {
|
||||
BlocProvider.of<RoutineBloc>(context)
|
||||
.add(
|
||||
|
@ -1,6 +1,5 @@
|
||||
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/routines/bloc/routine_bloc/routine_bloc.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/dragable_card.dart';
|
||||
|
||||
@ -18,6 +17,8 @@ class _RoutineDevicesState extends State<RoutineDevices> {
|
||||
context.read<RoutineBloc>().add(FetchDevicesInRoutine());
|
||||
}
|
||||
|
||||
static const _allowedProductTypes = {'AC', '1G', '2G', '3G', 'WPS', 'GW'};
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<RoutineBloc, RoutineState>(
|
||||
@ -32,13 +33,8 @@ class _RoutineDevicesState extends State<RoutineDevices> {
|
||||
}
|
||||
});
|
||||
|
||||
List<AllDevicesModel> deviceList = state.devices
|
||||
.where((device) =>
|
||||
device.productType == 'AC' ||
|
||||
device.productType == '1G' ||
|
||||
device.productType == '2G' ||
|
||||
device.productType == '3G' ||
|
||||
device.productType == 'WPS')
|
||||
final deviceList = state.devices
|
||||
.where((device) => _allowedProductTypes.contains(device.productType))
|
||||
.toList();
|
||||
|
||||
return Wrap(
|
||||
@ -46,37 +42,32 @@ class _RoutineDevicesState extends State<RoutineDevices> {
|
||||
runSpacing: 10,
|
||||
children: deviceList.asMap().entries.map((entry) {
|
||||
final device = entry.value;
|
||||
|
||||
final deviceData = {
|
||||
'device': device,
|
||||
'imagePath': device.getDefaultIcon(device.productType),
|
||||
'title': device.name ?? '',
|
||||
'deviceId': device.uuid,
|
||||
'productType': device.productType,
|
||||
'functions': device.functions,
|
||||
'uniqueCustomId': '',
|
||||
};
|
||||
|
||||
if (state.searchText != null && state.searchText!.isNotEmpty) {
|
||||
return device.name!
|
||||
.toLowerCase()
|
||||
.contains(state.searchText!.toLowerCase())
|
||||
? DraggableCard(
|
||||
imagePath: device.getDefaultIcon(device.productType),
|
||||
title: device.name ?? '',
|
||||
deviceData: {
|
||||
'device': device,
|
||||
'imagePath': device.getDefaultIcon(device.productType),
|
||||
'title': device.name ?? '',
|
||||
'deviceId': device.uuid,
|
||||
'productType': device.productType,
|
||||
'functions': device.functions,
|
||||
'uniqueCustomId': '',
|
||||
},
|
||||
imagePath: deviceData['imagePath'] as String,
|
||||
title: deviceData['title'] as String,
|
||||
deviceData: deviceData,
|
||||
)
|
||||
: Container();
|
||||
: const SizedBox.shrink();
|
||||
} else {
|
||||
return DraggableCard(
|
||||
imagePath: device.getDefaultIcon(device.productType),
|
||||
title: device.name ?? '',
|
||||
deviceData: {
|
||||
'device': device,
|
||||
'imagePath': device.getDefaultIcon(device.productType),
|
||||
'title': device.name ?? '',
|
||||
'deviceId': device.uuid,
|
||||
'productType': device.productType,
|
||||
'functions': device.functions,
|
||||
'uniqueCustomId': '',
|
||||
},
|
||||
imagePath: deviceData['imagePath'] as String,
|
||||
title: deviceData['title'] as String,
|
||||
deviceData: deviceData,
|
||||
);
|
||||
}
|
||||
}).toList(),
|
||||
|
@ -0,0 +1,42 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||
|
||||
class RoutineDialogFunctionListTile extends StatelessWidget {
|
||||
const RoutineDialogFunctionListTile({
|
||||
super.key,
|
||||
required this.iconPath,
|
||||
required this.operationName,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
final String iconPath;
|
||||
final String operationName;
|
||||
final void Function() onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
leading: SvgPicture.asset(
|
||||
iconPath,
|
||||
width: 24,
|
||||
height: 24,
|
||||
placeholderBuilder: (context) => const SizedBox(
|
||||
width: 24,
|
||||
height: 24,
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
operationName,
|
||||
style: context.textTheme.bodyMedium,
|
||||
),
|
||||
trailing: const Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
size: 16,
|
||||
color: ColorsManager.textGray,
|
||||
),
|
||||
onTap: onTap,
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||
|
||||
class RoutineDialogSelectionListTile extends StatelessWidget {
|
||||
const RoutineDialogSelectionListTile({
|
||||
required this.iconPath,
|
||||
required this.description,
|
||||
required this.isSelected,
|
||||
required this.onTap,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final bool isSelected;
|
||||
final String iconPath;
|
||||
final String description;
|
||||
final void Function() onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
leading: SvgPicture.asset(
|
||||
iconPath,
|
||||
width: 24,
|
||||
height: 24,
|
||||
placeholderBuilder: (context) => Container(
|
||||
width: 24,
|
||||
height: 24,
|
||||
color: Colors.transparent,
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
description,
|
||||
style: context.textTheme.bodyMedium,
|
||||
),
|
||||
trailing: Icon(
|
||||
isSelected ? Icons.radio_button_checked : Icons.radio_button_unchecked,
|
||||
size: 24,
|
||||
color: isSelected
|
||||
? ColorsManager.primaryColorWithOpacity
|
||||
: ColorsManager.textGray,
|
||||
),
|
||||
onTap: onTap,
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
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/routines/bloc/functions_bloc/functions_bloc_bloc.dart';
|
||||
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
||||
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
|
||||
import 'package:syncrow_web/pages/routines/models/gateway.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/dialog_footer.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/dialog_header.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/gateway/gateway_dialog_value_selector.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/gateway/gateway_functions_list.dart';
|
||||
|
||||
class GatewayDialog extends StatefulWidget {
|
||||
const GatewayDialog({
|
||||
required this.uniqueCustomId,
|
||||
required this.functions,
|
||||
required this.deviceSelectedFunctions,
|
||||
required this.device,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final String? uniqueCustomId;
|
||||
final List<DeviceFunction> functions;
|
||||
final List<DeviceFunctionData> deviceSelectedFunctions;
|
||||
final AllDevicesModel? device;
|
||||
|
||||
@override
|
||||
State<GatewayDialog> createState() => _GatewayDialogState();
|
||||
}
|
||||
|
||||
class _GatewayDialogState extends State<GatewayDialog> {
|
||||
late final List<GatewayFunctions> _gatewayFunctions;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_gatewayFunctions = widget.functions.whereType<GatewayFunctions>().toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
content: BlocBuilder<FunctionBloc, FunctionBlocState>(
|
||||
builder: (context, state) {
|
||||
final selectedFunction = state.selectedFunction;
|
||||
return Container(
|
||||
width: selectedFunction != null ? 600 : 360,
|
||||
height: 450,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
padding: const EdgeInsets.only(top: 20),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const DialogHeader('Gateway Conditions'),
|
||||
Expanded(child: _buildMainContent(context, state)),
|
||||
_buildDialogFooter(context, state),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMainContent(BuildContext context, FunctionBlocState state) {
|
||||
final selectedFunction = state.selectedFunction;
|
||||
final selectedOperationName = state.selectedOperationName;
|
||||
final selectedFunctionData = state.addedFunctions.firstWhere(
|
||||
(f) => f.functionCode == selectedFunction,
|
||||
orElse: () => DeviceFunctionData(
|
||||
entityId: '',
|
||||
functionCode: selectedFunction ?? '',
|
||||
operationName: '',
|
||||
value: null,
|
||||
),
|
||||
);
|
||||
final selectedGatewayFunctions = _gatewayFunctions.firstWhere(
|
||||
(f) => f.code == selectedFunction,
|
||||
orElse: () => GatewaySwitchAlarmSound(
|
||||
deviceId: '',
|
||||
deviceName: '',
|
||||
type: '',
|
||||
),
|
||||
);
|
||||
final operations = selectedGatewayFunctions.getOperationalValues();
|
||||
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
GatewayFunctionsList(gatewayFunctions: _gatewayFunctions),
|
||||
if (state.selectedFunction != null)
|
||||
Expanded(
|
||||
child: GatewayDialogValueSelector(
|
||||
operations: operations,
|
||||
selectedFunction: selectedFunction ?? '',
|
||||
selectedFunctionData: selectedFunctionData,
|
||||
gatewayFunctions: _gatewayFunctions,
|
||||
operationName: selectedOperationName ?? '',
|
||||
device: widget.device,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDialogFooter(BuildContext context, FunctionBlocState state) {
|
||||
return DialogFooter(
|
||||
onCancel: () => Navigator.pop(context),
|
||||
onConfirm: state.addedFunctions.isNotEmpty
|
||||
? () {
|
||||
context.read<RoutineBloc>().add(
|
||||
AddFunctionToRoutine(
|
||||
state.addedFunctions,
|
||||
widget.uniqueCustomId ?? '-1',
|
||||
),
|
||||
);
|
||||
Navigator.pop(
|
||||
context,
|
||||
{'deviceId': widget.functions.firstOrNull?.deviceId},
|
||||
);
|
||||
}
|
||||
: null,
|
||||
isConfirmEnabled: state.selectedFunction != null,
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
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/routines/bloc/functions_bloc/functions_bloc_bloc.dart';
|
||||
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
|
||||
import 'package:syncrow_web/pages/routines/models/gateway.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialog_selection_list_tile.dart';
|
||||
|
||||
class GatewayDialogValueSelector extends StatelessWidget {
|
||||
const GatewayDialogValueSelector({
|
||||
required this.operations,
|
||||
required this.selectedFunction,
|
||||
required this.selectedFunctionData,
|
||||
required this.gatewayFunctions,
|
||||
required this.device,
|
||||
required this.operationName,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final List<GatewayOperationalValue> operations;
|
||||
final String selectedFunction;
|
||||
final DeviceFunctionData? selectedFunctionData;
|
||||
final List<GatewayFunctions> gatewayFunctions;
|
||||
final AllDevicesModel? device;
|
||||
final String operationName;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView.builder(
|
||||
itemCount: operations.length,
|
||||
itemBuilder: (context, index) {
|
||||
final operation = operations[index];
|
||||
final isSelected = selectedFunctionData?.value == operation.value;
|
||||
return RoutineDialogSelectionListTile(
|
||||
iconPath: operation.icon,
|
||||
description: operation.description,
|
||||
isSelected: isSelected,
|
||||
onTap: () {
|
||||
if (!isSelected) {
|
||||
context.read<FunctionBloc>().add(
|
||||
AddFunction(
|
||||
functionData: DeviceFunctionData(
|
||||
entityId: device?.uuid ?? '',
|
||||
functionCode: selectedFunction,
|
||||
operationName: operationName,
|
||||
value: operation.value,
|
||||
condition: selectedFunctionData?.condition,
|
||||
valueDescription: selectedFunctionData?.valueDescription,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/routines/bloc/functions_bloc/functions_bloc_bloc.dart';
|
||||
import 'package:syncrow_web/pages/routines/models/gateway.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialog_function_list_tile.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
|
||||
class GatewayFunctionsList extends StatelessWidget {
|
||||
const GatewayFunctionsList({
|
||||
required this.gatewayFunctions,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final List<GatewayFunctions> gatewayFunctions;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
width: 360,
|
||||
child: ListView.separated(
|
||||
shrinkWrap: false,
|
||||
itemCount: gatewayFunctions.length,
|
||||
separatorBuilder: (context, index) => const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 40.0),
|
||||
child: Divider(color: ColorsManager.dividerColor),
|
||||
),
|
||||
itemBuilder: (context, index) {
|
||||
final function = gatewayFunctions[index];
|
||||
return RoutineDialogFunctionListTile(
|
||||
iconPath: function.icon,
|
||||
operationName: function.operationName,
|
||||
onTap: () => context.read<FunctionBloc>().add(
|
||||
SelectFunction(
|
||||
functionCode: function.code,
|
||||
operationName: function.operationName,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
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/routines/bloc/functions_bloc/functions_bloc_bloc.dart';
|
||||
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/gateway/gateway_dialog.dart';
|
||||
|
||||
abstract final class GatewayHelper {
|
||||
const GatewayHelper._();
|
||||
|
||||
static Future<Map<String, dynamic>?> showGatewayFunctionsDialog({
|
||||
required BuildContext context,
|
||||
required List<DeviceFunction> functions,
|
||||
required String? uniqueCustomId,
|
||||
required List<DeviceFunctionData> deviceSelectedFunctions,
|
||||
required AllDevicesModel? device,
|
||||
}) async {
|
||||
return showDialog(
|
||||
context: context,
|
||||
builder: (context) => BlocProvider<FunctionBloc>(
|
||||
create: (context) => FunctionBloc()
|
||||
..add(
|
||||
InitializeFunctions(deviceSelectedFunctions),
|
||||
),
|
||||
child: GatewayDialog(
|
||||
uniqueCustomId: uniqueCustomId,
|
||||
functions: functions,
|
||||
deviceSelectedFunctions: deviceSelectedFunctions,
|
||||
device: device,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
|
||||
@ -28,9 +27,12 @@ class _TimeWheelPickerState extends State<TimeWheelPicker> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_hoursController = FixedExtentScrollController(initialItem: widget.initialHours);
|
||||
_minutesController = FixedExtentScrollController(initialItem: widget.initialMinutes);
|
||||
_secondsController = FixedExtentScrollController(initialItem: widget.initialSeconds);
|
||||
_hoursController =
|
||||
FixedExtentScrollController(initialItem: widget.initialHours);
|
||||
_minutesController =
|
||||
FixedExtentScrollController(initialItem: widget.initialMinutes);
|
||||
_secondsController =
|
||||
FixedExtentScrollController(initialItem: widget.initialSeconds);
|
||||
}
|
||||
|
||||
@override
|
||||
@ -47,6 +49,8 @@ class _TimeWheelPickerState extends State<TimeWheelPicker> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_hoursController.dispose();
|
||||
@ -61,26 +65,28 @@ class _TimeWheelPickerState extends State<TimeWheelPicker> {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
_buildPickerColumn(
|
||||
label: 'h',
|
||||
controller: _hoursController,
|
||||
itemCount: 24,
|
||||
onChanged: (value) => _handleTimeChange(
|
||||
value,
|
||||
_minutesController.selectedItem,
|
||||
_secondsController.selectedItem,
|
||||
),
|
||||
),
|
||||
label: 'h',
|
||||
controller: _hoursController,
|
||||
itemCount: 3,
|
||||
onChanged: (value) {
|
||||
_handleTimeChange(
|
||||
value,
|
||||
_minutesController.selectedItem,
|
||||
_secondsController.selectedItem,
|
||||
);
|
||||
}),
|
||||
const SizedBox(width: 5),
|
||||
_buildPickerColumn(
|
||||
label: 'm',
|
||||
controller: _minutesController,
|
||||
itemCount: 60,
|
||||
onChanged: (value) => _handleTimeChange(
|
||||
_hoursController.selectedItem,
|
||||
value,
|
||||
_secondsController.selectedItem,
|
||||
),
|
||||
),
|
||||
label: 'm',
|
||||
controller: _minutesController,
|
||||
itemCount: 60,
|
||||
onChanged: (value) {
|
||||
_handleTimeChange(
|
||||
_hoursController.selectedItem,
|
||||
value,
|
||||
_secondsController.selectedItem,
|
||||
);
|
||||
}),
|
||||
const SizedBox(width: 5),
|
||||
_buildPickerColumn(
|
||||
label: 's',
|
||||
@ -97,6 +103,19 @@ class _TimeWheelPickerState extends State<TimeWheelPicker> {
|
||||
}
|
||||
|
||||
void _handleTimeChange(int hours, int minutes, int seconds) {
|
||||
int total = hours * 3600 + minutes * 60 + seconds;
|
||||
if (total > 10000) {
|
||||
hours = 2;
|
||||
minutes = 46;
|
||||
seconds = 40;
|
||||
total = 10000;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_hoursController.jumpToItem(hours);
|
||||
_minutesController.jumpToItem(minutes);
|
||||
_secondsController.jumpToItem(seconds);
|
||||
});
|
||||
}
|
||||
|
||||
widget.onTimeChanged(hours, minutes, seconds);
|
||||
}
|
||||
|
||||
@ -147,4 +166,4 @@ class _TimeWheelPickerState extends State<TimeWheelPicker> {
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +113,8 @@ class ThenContainer extends StatelessWidget {
|
||||
'1G',
|
||||
'2G',
|
||||
'3G',
|
||||
'WPS'
|
||||
'WPS',
|
||||
"GW",
|
||||
].contains(state.thenItems[index]
|
||||
['productType'])) {
|
||||
context.read<RoutineBloc>().add(
|
||||
@ -229,7 +230,7 @@ class ThenContainer extends StatelessWidget {
|
||||
dialogType: "THEN");
|
||||
if (result != null) {
|
||||
context.read<RoutineBloc>().add(AddToThenContainer(mutableData));
|
||||
} else if (!['AC', '1G', '2G', '3G', 'WPS']
|
||||
} else if (!['AC', '1G', '2G', '3G', 'WPS', 'GW']
|
||||
.contains(mutableData['productType'])) {
|
||||
context.read<RoutineBloc>().add(AddToThenContainer(mutableData));
|
||||
}
|
||||
|
@ -0,0 +1,51 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_event.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/create_community/view/create_community_dialog.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
|
||||
class SidebarAddCommunityButton extends StatelessWidget {
|
||||
const SidebarAddCommunityButton({
|
||||
required this.existingCommunityNames,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final List<String> existingCommunityNames;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox.square(
|
||||
dimension: 30,
|
||||
child: IconButton(
|
||||
style: IconButton.styleFrom(
|
||||
iconSize: 20,
|
||||
backgroundColor: ColorsManager.circleImageBackground,
|
||||
shape: const CircleBorder(
|
||||
side: BorderSide(
|
||||
color: ColorsManager.lightGrayBorderColor,
|
||||
width: 3,
|
||||
),
|
||||
),
|
||||
),
|
||||
onPressed: () => _showCreateCommunityDialog(context),
|
||||
icon: SvgPicture.asset(Assets.addIcon),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showCreateCommunityDialog(BuildContext context) => showDialog<void>(
|
||||
context: context,
|
||||
builder: (context) => CreateCommunityDialog(
|
||||
isEditMode: false,
|
||||
existingCommunityNames: existingCommunityNames,
|
||||
onCreateCommunity: (name, description) {
|
||||
context.read<SpaceManagementBloc>().add(
|
||||
CreateCommunityEvent(name, description, context),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/sidebar_add_community_button.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||
import 'package:syncrow_web/utils/style.dart';
|
||||
|
||||
class SidebarHeader extends StatelessWidget {
|
||||
const SidebarHeader({required this.existingCommunityNames, super.key});
|
||||
|
||||
final List<String> existingCommunityNames;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: subSectionContainerDecoration,
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'Communities',
|
||||
style: context.textTheme.titleMedium?.copyWith(
|
||||
color: ColorsManager.blackColor,
|
||||
),
|
||||
),
|
||||
SidebarAddCommunityButton(existingCommunityNames: existingCommunityNames),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -1,17 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:syncrow_web/common/widgets/search_bar.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_event.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/community_tile.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/sidebar_header.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/space_tile_widget.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/structure_selector/bloc/center_body_bloc.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/structure_selector/bloc/center_body_event.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:syncrow_web/utils/style.dart';
|
||||
|
||||
class SidebarWidget extends StatefulWidget {
|
||||
@ -19,62 +17,59 @@ class SidebarWidget extends StatefulWidget {
|
||||
final String? selectedSpaceUuid;
|
||||
|
||||
const SidebarWidget({
|
||||
super.key,
|
||||
required this.communities,
|
||||
this.selectedSpaceUuid,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
_SidebarWidgetState createState() => _SidebarWidgetState();
|
||||
State<SidebarWidget> createState() => _SidebarWidgetState();
|
||||
}
|
||||
|
||||
class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
String _searchQuery = ''; // Track search query
|
||||
String _searchQuery = '';
|
||||
String? _selectedSpaceUuid;
|
||||
String? _selectedId;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_selectedId = widget.selectedSpaceUuid;
|
||||
super.initState();
|
||||
_selectedId = widget.selectedSpaceUuid; // Initialize with the passed selected space UUID
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant SidebarWidget oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.selectedSpaceUuid != oldWidget.selectedSpaceUuid) {
|
||||
setState(() {
|
||||
_selectedId = widget.selectedSpaceUuid;
|
||||
});
|
||||
setState(() => _selectedId = widget.selectedSpaceUuid);
|
||||
}
|
||||
super.didUpdateWidget(oldWidget);
|
||||
}
|
||||
|
||||
// Function to filter communities based on the search query
|
||||
List<CommunityModel> _filterCommunities() {
|
||||
List<CommunityModel> _filteredCommunities() {
|
||||
if (_searchQuery.isEmpty) {
|
||||
// Reset the selected community and space UUIDs if there's no query
|
||||
_selectedSpaceUuid = null;
|
||||
return widget.communities;
|
||||
}
|
||||
|
||||
// Filter communities and expand only those that match the query
|
||||
return widget.communities.where((community) {
|
||||
final containsQueryInCommunity =
|
||||
community.name.toLowerCase().contains(_searchQuery.toLowerCase());
|
||||
final containsQueryInSpaces =
|
||||
community.spaces.any((space) => _containsQuery(space, _searchQuery.toLowerCase()));
|
||||
final containsQueryInSpaces = community.spaces.any((space) =>
|
||||
_containsQuery(space: space, query: _searchQuery.toLowerCase()));
|
||||
|
||||
return containsQueryInCommunity || containsQueryInSpaces;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
// Helper function to determine if any space or its children match the search query
|
||||
bool _containsQuery(SpaceModel space, String query) {
|
||||
bool _containsQuery({
|
||||
required SpaceModel space,
|
||||
required String query,
|
||||
}) {
|
||||
final matchesSpace = space.name.toLowerCase().contains(query);
|
||||
final matchesChildren =
|
||||
space.children.any((child) => _containsQuery(child, query)); // Recursive check for children
|
||||
final matchesChildren = space.children.any(
|
||||
(child) => _containsQuery(space: child, query: query),
|
||||
);
|
||||
|
||||
// If the space or any of its children match the query, expand this space
|
||||
if (matchesSpace || matchesChildren) {
|
||||
_selectedSpaceUuid = space.uuid;
|
||||
}
|
||||
@ -83,79 +78,35 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
}
|
||||
|
||||
bool _isSpaceOrChildSelected(SpaceModel space) {
|
||||
// Return true if the current space or any of its child spaces is selected
|
||||
if (_selectedSpaceUuid == space.uuid) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Recursively check if any child spaces match the query
|
||||
for (var child in space.children) {
|
||||
if (_isSpaceOrChildSelected(child)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
final isSpaceSelected = _selectedSpaceUuid == space.uuid;
|
||||
final anySubSpaceIsSelected = space.children.any(_isSpaceOrChildSelected);
|
||||
return isSpaceSelected || anySubSpaceIsSelected;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final filteredCommunities = _filterCommunities();
|
||||
final filteredCommunities = _filteredCommunities();
|
||||
|
||||
return Container(
|
||||
width: 300,
|
||||
decoration: subSectionContainerDecoration,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min, // Ensures the Column only takes necessary height
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Communities title with the add button
|
||||
Container(
|
||||
decoration: subSectionContainerDecoration,
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('Communities',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
color: ColorsManager.blackColor,
|
||||
)),
|
||||
GestureDetector(
|
||||
onTap: () => _navigateToBlank(context),
|
||||
child: Container(
|
||||
width: 30,
|
||||
height: 30,
|
||||
decoration: const BoxDecoration(
|
||||
color: ColorsManager.whiteColors,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Center(
|
||||
child: SvgPicture.asset(
|
||||
Assets.roundedAddIcon,
|
||||
width: 24,
|
||||
height: 24,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SidebarHeader(
|
||||
existingCommunityNames:
|
||||
widget.communities.map((community) => community.name).toList(),
|
||||
),
|
||||
// Search bar
|
||||
CustomSearchBar(
|
||||
onSearchChanged: (query) {
|
||||
setState(() {
|
||||
_searchQuery = query;
|
||||
});
|
||||
},
|
||||
onSearchChanged: (query) => setState(() => _searchQuery = query),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// Community list
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: filteredCommunities.map((community) {
|
||||
return _buildCommunityTile(context, community);
|
||||
}).toList(),
|
||||
children: filteredCommunities
|
||||
.map((community) => _buildCommunityTile(context, community))
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
],
|
||||
@ -163,18 +114,7 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
);
|
||||
}
|
||||
|
||||
void _navigateToBlank(BuildContext context) {
|
||||
setState(() {
|
||||
_selectedId = '';
|
||||
});
|
||||
context.read<SpaceManagementBloc>().add(
|
||||
NewCommunityEvent(communities: widget.communities),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCommunityTile(BuildContext context, CommunityModel community) {
|
||||
bool hasChildren = community.spaces.isNotEmpty;
|
||||
|
||||
return CommunityTile(
|
||||
title: community.name,
|
||||
key: ValueKey(community.uuid),
|
||||
@ -183,7 +123,7 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
onItemSelected: () {
|
||||
setState(() {
|
||||
_selectedId = community.uuid;
|
||||
_selectedSpaceUuid = null; // Update the selected community
|
||||
_selectedSpaceUuid = null;
|
||||
});
|
||||
|
||||
context.read<CenterBodyBloc>().add(CommunitySelectedEvent());
|
||||
@ -192,46 +132,51 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
SelectCommunityEvent(selectedCommunity: community),
|
||||
);
|
||||
},
|
||||
onExpansionChanged: (String title, bool expanded) {
|
||||
_handleExpansionChange(community.uuid, expanded);
|
||||
},
|
||||
children: hasChildren
|
||||
? community.spaces
|
||||
.where((space) => (space.status != SpaceStatus.deleted ||
|
||||
space.status != SpaceStatus.parentDeleted))
|
||||
.map((space) => _buildSpaceTile(space, community))
|
||||
.toList()
|
||||
: null,
|
||||
onExpansionChanged: (title, expanded) {},
|
||||
children: community.spaces
|
||||
.where((space) {
|
||||
final isDeleted = space.status != SpaceStatus.deleted;
|
||||
final isParentDeleted = space.status != SpaceStatus.parentDeleted;
|
||||
return (isDeleted || isParentDeleted);
|
||||
})
|
||||
.map((space) => _buildSpaceTile(space: space, community: community))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSpaceTile(SpaceModel space, CommunityModel community, {int depth = 1}) {
|
||||
bool isExpandedSpace = _isSpaceOrChildSelected(space);
|
||||
Widget _buildSpaceTile({
|
||||
required SpaceModel space,
|
||||
required CommunityModel community,
|
||||
}) {
|
||||
final spaceIsExpanded = _isSpaceOrChildSelected(space);
|
||||
final isSelected = _selectedId == space.uuid;
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(left: depth * 16.0),
|
||||
child: SpaceTile(
|
||||
title: space.name,
|
||||
key: ValueKey(space.uuid),
|
||||
isSelected: _selectedId == space.uuid,
|
||||
initiallyExpanded: isExpandedSpace,
|
||||
onExpansionChanged: (bool expanded) {
|
||||
_handleExpansionChange(space.uuid ?? '', expanded);
|
||||
},
|
||||
onItemSelected: () {
|
||||
setState(() {
|
||||
_selectedId = space.uuid;
|
||||
_selectedSpaceUuid = space.uuid;
|
||||
});
|
||||
padding: const EdgeInsetsDirectional.only(start: 16.0),
|
||||
child: SpaceTile(
|
||||
title: space.name,
|
||||
key: ValueKey(space.uuid),
|
||||
isSelected: isSelected,
|
||||
initiallyExpanded: spaceIsExpanded,
|
||||
onExpansionChanged: (expanded) {},
|
||||
onItemSelected: () {
|
||||
setState(() {
|
||||
_selectedId = space.uuid;
|
||||
_selectedSpaceUuid = space.uuid;
|
||||
});
|
||||
|
||||
context.read<SpaceManagementBloc>().add(
|
||||
SelectSpaceEvent(selectedCommunity: community, selectedSpace: space),
|
||||
);
|
||||
},
|
||||
children: space.children.isNotEmpty
|
||||
? space.children.map((childSpace) => _buildSpaceTile(childSpace, community)).toList()
|
||||
: [], // Recursively render child spaces if available
|
||||
));
|
||||
context.read<SpaceManagementBloc>().add(
|
||||
SelectSpaceEvent(selectedCommunity: community, selectedSpace: space),
|
||||
);
|
||||
},
|
||||
children: space.children
|
||||
.map(
|
||||
(childSpace) => _buildSpaceTile(
|
||||
space: childSpace,
|
||||
community: community,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _handleExpansionChange(String uuid, bool expanded) {}
|
||||
}
|
||||
|
@ -426,5 +426,8 @@ class Assets {
|
||||
static const String motionDetectionSensitivityValueIcon = 'assets/icons/motion_detection_sensitivity_value_icon.svg';
|
||||
static const String presenceTimeIcon = 'assets/icons/presence_time_icon.svg';
|
||||
static const String IlluminanceIcon = 'assets/icons/Illuminance_icon.svg';
|
||||
static const String gear = 'assets/icons/gear.svg';
|
||||
static const String activeBell='assets/icons/active_bell.svg';
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user