mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-15 01:35:25 +00:00
push garage door preferences
This commit is contained in:
@ -33,12 +33,16 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
|||||||
on<UpdateFunctionOnEvent>(_updateFunctionOn);
|
on<UpdateFunctionOnEvent>(_updateFunctionOn);
|
||||||
on<InitializeAddScheduleEvent>(_initializeAddSchedule);
|
on<InitializeAddScheduleEvent>(_initializeAddSchedule);
|
||||||
on<BackToGarageDoorGridViewEvent>(_backToGridView);
|
on<BackToGarageDoorGridViewEvent>(_backToGridView);
|
||||||
|
on<UpdateCountdownAlarmEvent>(_onUpdateCountdownAlarm);
|
||||||
|
on<UpdateTrTimeConEvent>(_onUpdateTrTimeCon);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchGarageDoorStatus(GarageDoorInitialEvent event, Emitter<GarageDoorState> emit) async {
|
void _fetchGarageDoorStatus(
|
||||||
|
GarageDoorInitialEvent event, Emitter<GarageDoorState> emit) async {
|
||||||
emit(GarageDoorLoadingState());
|
emit(GarageDoorLoadingState());
|
||||||
try {
|
try {
|
||||||
var response = await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
var response =
|
||||||
|
await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||||
deviceStatus = GarageDoorStatusModel.fromJson(deviceId, response.status);
|
deviceStatus = GarageDoorStatusModel.fromJson(deviceId, response.status);
|
||||||
emit(GarageDoorLoadedState(status: deviceStatus));
|
emit(GarageDoorLoadedState(status: deviceStatus));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -46,7 +50,8 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _addSchedule(AddGarageDoorScheduleEvent event, Emitter<GarageDoorState> emit) async {
|
Future<void> _addSchedule(
|
||||||
|
AddGarageDoorScheduleEvent event, Emitter<GarageDoorState> emit) async {
|
||||||
try {
|
try {
|
||||||
ScheduleEntry newSchedule = ScheduleEntry(
|
ScheduleEntry newSchedule = ScheduleEntry(
|
||||||
category: event.category,
|
category: event.category,
|
||||||
@ -54,9 +59,11 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
|||||||
function: Status(code: 'switch_1', value: event.functionOn),
|
function: Status(code: 'switch_1', value: event.functionOn),
|
||||||
days: ScheduleModel.convertSelectedDaysToStrings(event.selectedDays),
|
days: ScheduleModel.convertSelectedDaysToStrings(event.selectedDays),
|
||||||
);
|
);
|
||||||
bool success = await DevicesManagementApi().addScheduleRecord(newSchedule, deviceId);
|
bool success =
|
||||||
|
await DevicesManagementApi().addScheduleRecord(newSchedule, deviceId);
|
||||||
if (success) {
|
if (success) {
|
||||||
add(FetchGarageDoorSchedulesEvent(deviceId: deviceId, category: 'switch_1'));
|
add(FetchGarageDoorSchedulesEvent(
|
||||||
|
deviceId: deviceId, category: 'switch_1'));
|
||||||
} else {
|
} else {
|
||||||
emit(GarageDoorLoadedState(status: deviceStatus));
|
emit(GarageDoorLoadedState(status: deviceStatus));
|
||||||
}
|
}
|
||||||
@ -65,7 +72,29 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _updateSchedule(UpdateGarageDoorScheduleEvent event, Emitter<GarageDoorState> emit) async {
|
void _onUpdateCountdownAlarm(
|
||||||
|
UpdateCountdownAlarmEvent event, Emitter<GarageDoorState> emit) {
|
||||||
|
final currentState = state;
|
||||||
|
if (currentState is GarageDoorLoadedState) {
|
||||||
|
emit(currentState.copyWith(
|
||||||
|
status:
|
||||||
|
currentState.status.copyWith(countdownAlarm: event.countdownAlarm),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onUpdateTrTimeCon(
|
||||||
|
UpdateTrTimeConEvent event, Emitter<GarageDoorState> emit) {
|
||||||
|
final currentState = state;
|
||||||
|
if (currentState is GarageDoorLoadedState) {
|
||||||
|
emit(currentState.copyWith(
|
||||||
|
status: currentState.status.copyWith(trTimeCon: event.trTimeCon),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _updateSchedule(UpdateGarageDoorScheduleEvent event,
|
||||||
|
Emitter<GarageDoorState> emit) async {
|
||||||
try {
|
try {
|
||||||
final updatedSchedules = deviceStatus.schedules?.map((schedule) {
|
final updatedSchedules = deviceStatus.schedules?.map((schedule) {
|
||||||
if (schedule.scheduleId == event.scheduleId) {
|
if (schedule.scheduleId == event.scheduleId) {
|
||||||
@ -92,12 +121,15 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _deleteSchedule(DeleteGarageDoorScheduleEvent event, Emitter<GarageDoorState> emit) async {
|
Future<void> _deleteSchedule(DeleteGarageDoorScheduleEvent event,
|
||||||
|
Emitter<GarageDoorState> emit) async {
|
||||||
try {
|
try {
|
||||||
bool success = await DevicesManagementApi().deleteScheduleRecord(deviceStatus.uuid, event.scheduleId);
|
bool success = await DevicesManagementApi()
|
||||||
|
.deleteScheduleRecord(deviceStatus.uuid, event.scheduleId);
|
||||||
if (success) {
|
if (success) {
|
||||||
final updatedSchedules =
|
final updatedSchedules = deviceStatus.schedules
|
||||||
deviceStatus.schedules?.where((schedule) => schedule.scheduleId != event.scheduleId).toList();
|
?.where((schedule) => schedule.scheduleId != event.scheduleId)
|
||||||
|
.toList();
|
||||||
deviceStatus = deviceStatus.copyWith(schedules: updatedSchedules);
|
deviceStatus = deviceStatus.copyWith(schedules: updatedSchedules);
|
||||||
emit(GarageDoorLoadedState(status: deviceStatus));
|
emit(GarageDoorLoadedState(status: deviceStatus));
|
||||||
} else {
|
} else {
|
||||||
@ -108,11 +140,12 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _fetchSchedules(FetchGarageDoorSchedulesEvent event, Emitter<GarageDoorState> emit) async {
|
Future<void> _fetchSchedules(FetchGarageDoorSchedulesEvent event,
|
||||||
|
Emitter<GarageDoorState> emit) async {
|
||||||
emit(ScheduleGarageLoadingState());
|
emit(ScheduleGarageLoadingState());
|
||||||
try {
|
try {
|
||||||
List<ScheduleModel> schedules =
|
List<ScheduleModel> schedules = await DevicesManagementApi()
|
||||||
await DevicesManagementApi().getDeviceSchedules(deviceStatus.uuid, event.category);
|
.getDeviceSchedules(deviceStatus.uuid, event.category);
|
||||||
deviceStatus = deviceStatus.copyWith(schedules: schedules);
|
deviceStatus = deviceStatus.copyWith(schedules: schedules);
|
||||||
emit(
|
emit(
|
||||||
GarageDoorLoadedState(
|
GarageDoorLoadedState(
|
||||||
@ -130,30 +163,37 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _updateSelectedTime(UpdateSelectedTimeEvent event, Emitter<GarageDoorState> emit) async {
|
Future<void> _updateSelectedTime(
|
||||||
|
UpdateSelectedTimeEvent event, Emitter<GarageDoorState> emit) async {
|
||||||
final currentState = state;
|
final currentState = state;
|
||||||
if (currentState is GarageDoorLoadedState) {
|
if (currentState is GarageDoorLoadedState) {
|
||||||
emit(currentState.copyWith(selectedTime: event.selectedTime));
|
emit(currentState.copyWith(selectedTime: event.selectedTime));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _updateSelectedDay(UpdateSelectedDayEvent event, Emitter<GarageDoorState> emit) async {
|
Future<void> _updateSelectedDay(
|
||||||
|
UpdateSelectedDayEvent event, Emitter<GarageDoorState> emit) async {
|
||||||
final currentState = state;
|
final currentState = state;
|
||||||
if (currentState is GarageDoorLoadedState) {
|
if (currentState is GarageDoorLoadedState) {
|
||||||
List<bool> updatedDays = List.from(currentState.selectedDays);
|
List<bool> updatedDays = List.from(currentState.selectedDays);
|
||||||
updatedDays[event.dayIndex] = event.isSelected;
|
updatedDays[event.dayIndex] = event.isSelected;
|
||||||
emit(currentState.copyWith(selectedDays: updatedDays, selectedTime: currentState.selectedTime));
|
emit(currentState.copyWith(
|
||||||
|
selectedDays: updatedDays, selectedTime: currentState.selectedTime));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _updateFunctionOn(UpdateFunctionOnEvent event, Emitter<GarageDoorState> emit) async {
|
Future<void> _updateFunctionOn(
|
||||||
|
UpdateFunctionOnEvent event, Emitter<GarageDoorState> emit) async {
|
||||||
final currentState = state;
|
final currentState = state;
|
||||||
if (currentState is GarageDoorLoadedState) {
|
if (currentState is GarageDoorLoadedState) {
|
||||||
emit(currentState.copyWith(functionOn: event.functionOn, selectedTime: currentState.selectedTime));
|
emit(currentState.copyWith(
|
||||||
|
functionOn: event.functionOn,
|
||||||
|
selectedTime: currentState.selectedTime));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _initializeAddSchedule(InitializeAddScheduleEvent event, Emitter<GarageDoorState> emit) async {
|
Future<void> _initializeAddSchedule(
|
||||||
|
InitializeAddScheduleEvent event, Emitter<GarageDoorState> emit) async {
|
||||||
final currentState = state;
|
final currentState = state;
|
||||||
if (currentState is GarageDoorLoadedState) {
|
if (currentState is GarageDoorLoadedState) {
|
||||||
emit(currentState.copyWith(
|
emit(currentState.copyWith(
|
||||||
@ -165,24 +205,30 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _fetchRecords(FetchGarageDoorRecordsEvent event, Emitter<GarageDoorState> emit) async {
|
Future<void> _fetchRecords(
|
||||||
|
FetchGarageDoorRecordsEvent event, Emitter<GarageDoorState> emit) async {
|
||||||
emit(GarageDoorReportsLoadingState());
|
emit(GarageDoorReportsLoadingState());
|
||||||
try {
|
try {
|
||||||
final from = DateTime.now().subtract(const Duration(days: 30)).millisecondsSinceEpoch;
|
final from = DateTime.now()
|
||||||
|
.subtract(const Duration(days: 30))
|
||||||
|
.millisecondsSinceEpoch;
|
||||||
final to = DateTime.now().millisecondsSinceEpoch;
|
final to = DateTime.now().millisecondsSinceEpoch;
|
||||||
final DeviceReport records =
|
final DeviceReport records =
|
||||||
await DevicesManagementApi.getDeviceReportsByDate(event.deviceId, 'switch_1', from.toString(), to.toString());
|
await DevicesManagementApi.getDeviceReportsByDate(
|
||||||
|
event.deviceId, 'switch_1', from.toString(), to.toString());
|
||||||
emit(GarageDoorReportsState(deviceReport: records));
|
emit(GarageDoorReportsState(deviceReport: records));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(GarageDoorReportsFailedState(error: e.toString()));
|
emit(GarageDoorReportsFailedState(error: e.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _backToGridView(BackToGarageDoorGridViewEvent event, Emitter<GarageDoorState> emit) {
|
void _backToGridView(
|
||||||
|
BackToGarageDoorGridViewEvent event, Emitter<GarageDoorState> emit) {
|
||||||
emit(GarageDoorLoadedState(status: deviceStatus));
|
emit(GarageDoorLoadedState(status: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleUpdate(GarageDoorUpdatedEvent event, Emitter<GarageDoorState> emit) {
|
void _handleUpdate(
|
||||||
|
GarageDoorUpdatedEvent event, Emitter<GarageDoorState> emit) {
|
||||||
emit(GarageDoorLoadedState(status: deviceStatus));
|
emit(GarageDoorLoadedState(status: deviceStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,9 +244,11 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
|||||||
late bool status;
|
late bool status;
|
||||||
await Future.delayed(const Duration(milliseconds: 500));
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
if (isBatch) {
|
if (isBatch) {
|
||||||
status = await DevicesManagementApi().deviceBatchControl(deviceId, code, value);
|
status = await DevicesManagementApi()
|
||||||
|
.deviceBatchControl(deviceId, code, value);
|
||||||
} else {
|
} else {
|
||||||
status = await DevicesManagementApi().deviceControl(deviceId, Status(code: code, value: value));
|
status = await DevicesManagementApi()
|
||||||
|
.deviceControl(deviceId, Status(code: code, value: value));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!status) {
|
if (!status) {
|
||||||
@ -215,34 +263,47 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _increaseDelay(IncreaseGarageDoorDelayEvent event, Emitter<GarageDoorState> emit) async {
|
void _increaseDelay(
|
||||||
|
IncreaseGarageDoorDelayEvent event, Emitter<GarageDoorState> emit) async {
|
||||||
// if (deviceStatus.countdown1 != 0) {
|
// if (deviceStatus.countdown1 != 0) {
|
||||||
try {
|
try {
|
||||||
deviceStatus = deviceStatus.copyWith(delay: deviceStatus.delay + Duration(minutes: 10));
|
deviceStatus = deviceStatus.copyWith(
|
||||||
|
delay: deviceStatus.delay + Duration(minutes: 10));
|
||||||
emit(GarageDoorLoadedState(status: deviceStatus));
|
emit(GarageDoorLoadedState(status: deviceStatus));
|
||||||
add(GarageDoorControlEvent(deviceId: event.deviceId, value: deviceStatus.delay.inSeconds, code: 'countdown_1'));
|
add(GarageDoorControlEvent(
|
||||||
|
deviceId: event.deviceId,
|
||||||
|
value: deviceStatus.delay.inSeconds,
|
||||||
|
code: 'countdown_1'));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(GarageDoorErrorState(message: e.toString()));
|
emit(GarageDoorErrorState(message: e.toString()));
|
||||||
}
|
}
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void _decreaseDelay(DecreaseGarageDoorDelayEvent event, Emitter<GarageDoorState> emit) async {
|
void _decreaseDelay(
|
||||||
|
DecreaseGarageDoorDelayEvent event, Emitter<GarageDoorState> emit) async {
|
||||||
// if (deviceStatus.countdown1 != 0) {
|
// if (deviceStatus.countdown1 != 0) {
|
||||||
try {
|
try {
|
||||||
if (deviceStatus.delay.inMinutes > 10) {
|
if (deviceStatus.delay.inMinutes > 10) {
|
||||||
deviceStatus = deviceStatus.copyWith(delay: deviceStatus.delay - Duration(minutes: 10));
|
deviceStatus = deviceStatus.copyWith(
|
||||||
|
delay: deviceStatus.delay - Duration(minutes: 10));
|
||||||
}
|
}
|
||||||
emit(GarageDoorLoadedState(status: deviceStatus));
|
emit(GarageDoorLoadedState(status: deviceStatus));
|
||||||
add(GarageDoorControlEvent(deviceId: event.deviceId, value: deviceStatus.delay.inSeconds, code: 'countdown_1'));
|
add(GarageDoorControlEvent(
|
||||||
|
deviceId: event.deviceId,
|
||||||
|
value: deviceStatus.delay.inSeconds,
|
||||||
|
code: 'countdown_1'));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(GarageDoorErrorState(message: e.toString()));
|
emit(GarageDoorErrorState(message: e.toString()));
|
||||||
}
|
}
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _garageDoorControlEvent(GarageDoorControlEvent event, Emitter<GarageDoorState> emit) async {
|
void _garageDoorControlEvent(
|
||||||
final oldValue = event.code == 'countdown_1' ? deviceStatus.countdown1 : deviceStatus.switch1;
|
GarageDoorControlEvent event, Emitter<GarageDoorState> emit) async {
|
||||||
|
final oldValue = event.code == 'countdown_1'
|
||||||
|
? deviceStatus.countdown1
|
||||||
|
: deviceStatus.switch1;
|
||||||
_updateLocalValue(event.code, event.value);
|
_updateLocalValue(event.code, event.value);
|
||||||
emit(GarageDoorLoadedState(status: deviceStatus));
|
emit(GarageDoorLoadedState(status: deviceStatus));
|
||||||
final success = await _runDeBouncer(
|
final success = await _runDeBouncer(
|
||||||
@ -258,7 +319,8 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _revertValue(String code, dynamic oldValue, Emitter<GarageDoorState> emit) {
|
void _revertValue(
|
||||||
|
String code, dynamic oldValue, Emitter<GarageDoorState> emit) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case 'switch_1':
|
case 'switch_1':
|
||||||
if (oldValue is bool) {
|
if (oldValue is bool) {
|
||||||
@ -267,7 +329,8 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
|||||||
break;
|
break;
|
||||||
case 'countdown_1':
|
case 'countdown_1':
|
||||||
if (oldValue is int) {
|
if (oldValue is int) {
|
||||||
deviceStatus = deviceStatus.copyWith(countdown1: oldValue, delay: Duration(seconds: oldValue));
|
deviceStatus = deviceStatus.copyWith(
|
||||||
|
countdown1: oldValue, delay: Duration(seconds: oldValue));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// Add other cases if needed
|
// Add other cases if needed
|
||||||
@ -289,10 +352,20 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
|||||||
break;
|
break;
|
||||||
case 'countdown_1':
|
case 'countdown_1':
|
||||||
if (value is int) {
|
if (value is int) {
|
||||||
deviceStatus = deviceStatus.copyWith(countdown1: value, delay: Duration(seconds: value));
|
deviceStatus = deviceStatus.copyWith(
|
||||||
|
countdown1: value, delay: Duration(seconds: value));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'countdown_alarm':
|
||||||
|
if (value is int) {
|
||||||
|
deviceStatus = deviceStatus.copyWith(countdownAlarm: value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'tr_timecon':
|
||||||
|
if (value is int) {
|
||||||
|
deviceStatus = deviceStatus.copyWith(trTimeCon: value);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// Add other cases if needed
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,8 @@ class GarageDoorControlEvent extends GarageDoorEvent {
|
|||||||
final dynamic value;
|
final dynamic value;
|
||||||
final String code;
|
final String code;
|
||||||
|
|
||||||
const GarageDoorControlEvent({required this.deviceId, required this.value, required this.code});
|
const GarageDoorControlEvent(
|
||||||
|
{required this.deviceId, required this.value, required this.code});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [deviceId, value];
|
List<Object?> get props => [deviceId, value];
|
||||||
@ -104,7 +105,8 @@ class FetchGarageDoorRecordsEvent extends GarageDoorEvent {
|
|||||||
final String deviceId;
|
final String deviceId;
|
||||||
final String code;
|
final String code;
|
||||||
|
|
||||||
const FetchGarageDoorRecordsEvent({required this.deviceId, required this.code});
|
const FetchGarageDoorRecordsEvent(
|
||||||
|
{required this.deviceId, required this.code});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [deviceId, code];
|
List<Object?> get props => [deviceId, code];
|
||||||
@ -166,3 +168,15 @@ class InitializeAddScheduleEvent extends GarageDoorEvent {
|
|||||||
index,
|
index,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class UpdateCountdownAlarmEvent extends GarageDoorEvent {
|
||||||
|
final int countdownAlarm;
|
||||||
|
|
||||||
|
const UpdateCountdownAlarmEvent(this.countdownAlarm);
|
||||||
|
}
|
||||||
|
|
||||||
|
class UpdateTrTimeConEvent extends GarageDoorEvent {
|
||||||
|
final int trTimeCon;
|
||||||
|
|
||||||
|
const UpdateTrTimeConEvent(this.trTimeCon);
|
||||||
|
}
|
||||||
|
@ -291,6 +291,9 @@ class GarageDoorDialogHelper {
|
|||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(),
|
const SizedBox(),
|
||||||
|
|
||||||
|
/// The dialog is closed when the user taps on the close button or when the
|
||||||
|
/// [GarageDoorBloc] state changes.
|
||||||
Text(
|
Text(
|
||||||
'Preferences',
|
'Preferences',
|
||||||
style: context.textTheme.titleLarge!.copyWith(
|
style: context.textTheme.titleLarge!.copyWith(
|
||||||
@ -311,13 +314,32 @@ class GarageDoorDialogHelper {
|
|||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
context.customAlertDialog(
|
context.customAlertDialog(
|
||||||
alertBody: TimeOutAlarmDialogBody(),
|
alertBody: TimeOutAlarmDialogBody(bloc),
|
||||||
title: 'Time Out Alarm',
|
title: 'Time Out Alarm',
|
||||||
onConfirm: () {});
|
onConfirm: () {
|
||||||
|
final updatedState =
|
||||||
|
context.read<GarageDoorBloc>().state;
|
||||||
|
if (updatedState
|
||||||
|
is GarageDoorLoadedState) {
|
||||||
|
context.read<GarageDoorBloc>().add(
|
||||||
|
GarageDoorControlEvent(
|
||||||
|
deviceId:
|
||||||
|
updatedState.status.uuid,
|
||||||
|
code: 'countdown_alarm',
|
||||||
|
value: updatedState
|
||||||
|
.status.countdownAlarm,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
Navigator.pop(context);
|
||||||
|
// context.read<GarageDoorBloc>().add(
|
||||||
|
// GarageDoorInitialEvent(
|
||||||
|
// bloc.deviceId));
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
child: ToggleWidget(
|
child: ToggleWidget(
|
||||||
icon: "-1",
|
icon: "-1",
|
||||||
value: bloc.deviceStatus.countdownAlarm > 0,
|
value: state.status.countdownAlarm > 0,
|
||||||
code: 'countdown_alarm',
|
code: 'countdown_alarm',
|
||||||
deviceId: bloc.deviceId,
|
deviceId: bloc.deviceId,
|
||||||
label: 'Alarm when door is open',
|
label: 'Alarm when door is open',
|
||||||
@ -333,12 +355,38 @@ class GarageDoorDialogHelper {
|
|||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
context.customAlertDialog(
|
context.customAlertDialog(
|
||||||
alertBody: OpeningClosingTimeDialogBody(),
|
alertBody: OpeningAndClosingTimeDialogBody(
|
||||||
|
bloc: bloc,
|
||||||
|
onDurationChanged: (newDuration) {
|
||||||
|
context.read<GarageDoorBloc>().add(
|
||||||
|
UpdateTrTimeConEvent(newDuration),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
title: 'Opening and Closing Time',
|
title: 'Opening and Closing Time',
|
||||||
onConfirm: () {});
|
onConfirm: () {
|
||||||
|
final updatedState =
|
||||||
|
context.read<GarageDoorBloc>().state;
|
||||||
|
if (updatedState
|
||||||
|
is GarageDoorLoadedState) {
|
||||||
|
context.read<GarageDoorBloc>().add(
|
||||||
|
GarageDoorControlEvent(
|
||||||
|
deviceId:
|
||||||
|
updatedState.status.uuid,
|
||||||
|
code: 'tr_timecon',
|
||||||
|
value: updatedState
|
||||||
|
.status.trTimeCon,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
Navigator.pop(context);
|
||||||
|
// context.read<GarageDoorBloc>().add(
|
||||||
|
// GarageDoorInitialEvent(
|
||||||
|
// bloc.deviceId));
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
child: PresenceDisplayValue(
|
child: PresenceDisplayValue(
|
||||||
value: bloc.deviceStatus.trTimeCon.toString(),
|
value: state.status.trTimeCon.toString(),
|
||||||
postfix: 'sec',
|
postfix: 'sec',
|
||||||
description: 'Opening & Closing Time',
|
description: 'Opening & Closing Time',
|
||||||
),
|
),
|
||||||
|
@ -1,13 +1,53 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/garage_door/bloc/garage_door_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/garage_door/bloc/garage_door_state.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/garage_door/widgets/seconds_picker.dart';
|
||||||
|
|
||||||
class OpeningClosingTimeDialogBody extends StatelessWidget {
|
class OpeningAndClosingTimeDialogBody extends StatefulWidget {
|
||||||
const OpeningClosingTimeDialogBody({super.key});
|
final ValueChanged<int> onDurationChanged;
|
||||||
|
final GarageDoorBloc bloc;
|
||||||
|
|
||||||
|
OpeningAndClosingTimeDialogBody({
|
||||||
|
required this.onDurationChanged,
|
||||||
|
required this.bloc,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_OpeningAndClosingTimeDialogBodyState createState() =>
|
||||||
|
_OpeningAndClosingTimeDialogBodyState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _OpeningAndClosingTimeDialogBodyState
|
||||||
|
extends State<OpeningAndClosingTimeDialogBody> {
|
||||||
|
late int durationInSeconds;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeDependencies() {
|
||||||
|
super.didChangeDependencies();
|
||||||
|
|
||||||
|
final currentState = widget.bloc.state;
|
||||||
|
if (currentState is GarageDoorLoadedState) {
|
||||||
|
setState(() {
|
||||||
|
durationInSeconds = currentState.status.trTimeCon;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
width: 350,
|
height: 120,
|
||||||
child: Text('asdasd'),
|
color: Colors.white,
|
||||||
|
child: SecondsPicker(
|
||||||
|
initialSeconds: durationInSeconds,
|
||||||
|
onSecondsChanged: (newSeconds) {
|
||||||
|
setState(() {
|
||||||
|
durationInSeconds = newSeconds;
|
||||||
|
});
|
||||||
|
widget.onDurationChanged(newSeconds);
|
||||||
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class SecondsPicker extends StatefulWidget {
|
||||||
|
final int initialSeconds;
|
||||||
|
final ValueChanged<int> onSecondsChanged;
|
||||||
|
|
||||||
|
SecondsPicker({
|
||||||
|
required this.initialSeconds,
|
||||||
|
required this.onSecondsChanged,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_SecondsPickerState createState() => _SecondsPickerState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SecondsPickerState extends State<SecondsPicker> {
|
||||||
|
late FixedExtentScrollController _scrollController;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_scrollController = FixedExtentScrollController(
|
||||||
|
initialItem: widget.initialSeconds,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
height: 120,
|
||||||
|
color: Colors.white,
|
||||||
|
child: ListWheelScrollView.useDelegate(
|
||||||
|
controller: _scrollController,
|
||||||
|
itemExtent: 48,
|
||||||
|
onSelectedItemChanged: (index) {
|
||||||
|
widget.onSecondsChanged(index);
|
||||||
|
},
|
||||||
|
physics: const FixedExtentScrollPhysics(),
|
||||||
|
childDelegate: ListWheelChildBuilderDelegate(
|
||||||
|
builder: (context, index) {
|
||||||
|
return Center(
|
||||||
|
child: Text(
|
||||||
|
'$index sec',
|
||||||
|
style: const TextStyle(fontSize: 24),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +1,49 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/garage_door/bloc/garage_door_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/garage_door/bloc/garage_door_event.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/garage_door/bloc/garage_door_state.dart';
|
||||||
|
|
||||||
class TimeOutAlarmDialogBody extends StatelessWidget {
|
class TimeOutAlarmDialogBody extends StatefulWidget {
|
||||||
const TimeOutAlarmDialogBody({super.key});
|
TimeOutAlarmDialogBody(this.bloc);
|
||||||
|
final GarageDoorBloc bloc;
|
||||||
|
|
||||||
|
@override
|
||||||
|
_TimeOutAlarmDialogBodyState createState() => _TimeOutAlarmDialogBodyState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TimeOutAlarmDialogBodyState extends State<TimeOutAlarmDialogBody> {
|
||||||
|
int durationInSeconds = 0;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeDependencies() {
|
||||||
|
super.didChangeDependencies();
|
||||||
|
|
||||||
|
final currentState = widget.bloc.state;
|
||||||
|
if (currentState is GarageDoorLoadedState) {
|
||||||
|
if (currentState.status.countdownAlarm != 0) {
|
||||||
|
setState(() {
|
||||||
|
durationInSeconds = currentState.status.countdownAlarm;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
width: 350,
|
height: 120,
|
||||||
child: Text('asdasd'),
|
color: Colors.white,
|
||||||
|
child: CupertinoTimerPicker(
|
||||||
|
itemExtent: 120,
|
||||||
|
mode: CupertinoTimerPickerMode.hm,
|
||||||
|
initialTimerDuration: Duration(seconds: durationInSeconds),
|
||||||
|
onTimerDurationChanged: (newDuration) {
|
||||||
|
widget.bloc.add(
|
||||||
|
UpdateCountdownAlarmEvent(newDuration.inSeconds),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user