mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-27 16:34:55 +00:00
added automation flag in the the bloc and event
This commit is contained in:
@ -28,21 +28,45 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
on<UpdateTaskEvent>(_updateTaskValue);
|
||||
}
|
||||
|
||||
/// tab to run values and list
|
||||
List<SceneStaticFunction> tasksList = [];
|
||||
List<SceneStaticFunction> tempTasksList = [];
|
||||
final Map<String, dynamic> selectedValues = {};
|
||||
|
||||
/// automation values and list
|
||||
List<SceneStaticFunction> automationTasksList = [];
|
||||
List<SceneStaticFunction> automationTempTasksList = [];
|
||||
final Map<String, dynamic> automationSelectedValues = {};
|
||||
|
||||
FutureOr<void> _onAddSceneTask(
|
||||
AddTaskEvent event, Emitter<CreateSceneState> emit) {
|
||||
if (event.isAutomation == true) {
|
||||
final copyList = List<SceneStaticFunction>.from(automationTempTasksList);
|
||||
automationTasksList.addAll(copyList);
|
||||
automationTempTasksList.clear();
|
||||
automationSelectedValues.clear();
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
} else {
|
||||
final copyList = List<SceneStaticFunction>.from(tempTasksList);
|
||||
tasksList.addAll(copyList);
|
||||
tempTasksList.clear();
|
||||
selectedValues.clear();
|
||||
emit(AddSceneTask(tasksList: tasksList));
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _onTempHoldSceneTask(
|
||||
TempHoldSceneTasksEvent event, Emitter<CreateSceneState> emit) {
|
||||
if (event.isAutomation == true) {
|
||||
addToTempAutomationTaskList(event, emit);
|
||||
} else {
|
||||
addToTempTaskList(event, emit);
|
||||
}
|
||||
}
|
||||
|
||||
void addToTempTaskList(
|
||||
TempHoldSceneTasksEvent event, Emitter<CreateSceneState> emit) {
|
||||
bool updated = false;
|
||||
for (var element in tempTasksList) {
|
||||
if (element.code == event.deviceControlModel.code) {
|
||||
@ -54,6 +78,7 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
code: event.deviceControlModel.code ?? '',
|
||||
deviceId: event.deviceId,
|
||||
functionValue: event.deviceControlModel.value,
|
||||
operationDialogType: event.operationType,
|
||||
operationalValues: [
|
||||
SceneOperationalValue(
|
||||
value: event.deviceControlModel.value,
|
||||
@ -68,31 +93,12 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
}
|
||||
}
|
||||
if (!updated) {
|
||||
// Add new function if not found
|
||||
OperationDialogType getOperationDialogType(String? code, [value]) {
|
||||
if (code == null) {
|
||||
return OperationDialogType.none;
|
||||
}
|
||||
if (code.contains('delay')) {
|
||||
return OperationDialogType.delay;
|
||||
} else if (code.contains('countdown')) {
|
||||
return OperationDialogType.countdown;
|
||||
} else if (code.contains('set_temp')) {
|
||||
return OperationDialogType.temperature;
|
||||
} else if (value.toString().toLowerCase().trim() == 'on' ||
|
||||
value.toString().toLowerCase().trim() == 'off') {
|
||||
return OperationDialogType.onOff;
|
||||
}
|
||||
return OperationDialogType.listOfOptions;
|
||||
}
|
||||
|
||||
var newElement = SceneStaticFunction(
|
||||
operationName: event.operation,
|
||||
deviceName: event.deviceName,
|
||||
icon: event.icon,
|
||||
code: event.deviceControlModel.code ?? '',
|
||||
operationDialogType: getOperationDialogType(
|
||||
event.deviceControlModel.code, event.deviceControlModel.value),
|
||||
operationDialogType: event.operationType,
|
||||
deviceId: event.deviceId,
|
||||
functionValue: event.deviceControlModel.value,
|
||||
operationalValues: [
|
||||
@ -105,22 +111,37 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
tempTasksList.add(newElement);
|
||||
selectedValues[newElement.code] = event.deviceControlModel.value;
|
||||
}
|
||||
|
||||
emit(TempHoldSceneTask(tempTasksList: tempTasksList));
|
||||
emit(AddSceneTask(tasksList: tasksList));
|
||||
}
|
||||
|
||||
FutureOr<void> _selectedValue(
|
||||
SelectedValueEvent event, Emitter<CreateSceneState> emit) {
|
||||
if (event.isAutomation == true) {
|
||||
automationSelectedValues[event.code] = event.value;
|
||||
emit(SelectedTaskValueState(value: event.value));
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
} else {
|
||||
selectedValues[event.code] = event.value;
|
||||
emit(SelectedTaskValueState(value: event.value));
|
||||
emit(AddSceneTask(tasksList: tasksList));
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _removeTaskById(
|
||||
RemoveTaskByIdEvent event, Emitter<CreateSceneState> emit) {
|
||||
emit(CreateSceneLoading());
|
||||
|
||||
if (event.isAutomation == true) {
|
||||
for (var element in automationTasksList) {
|
||||
if (element.uniqueCustomId == event.taskId) {
|
||||
automationTasksList.remove(element);
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (var element in tasksList) {
|
||||
if (element.uniqueCustomId == event.taskId) {
|
||||
tasksList.remove(element);
|
||||
@ -130,9 +151,20 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _removeTempTaskById(
|
||||
RemoveTempTaskByIdEvent event, Emitter<CreateSceneState> emit) {
|
||||
if (event.isAutomation == true) {
|
||||
for (var element in automationTempTasksList) {
|
||||
if (element.uniqueCustomId == event.code) {
|
||||
automationTempTasksList.remove(element);
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (var element in tempTasksList) {
|
||||
if (element.code == event.code) {
|
||||
tempTasksList.remove(element);
|
||||
@ -143,6 +175,7 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _createSceneWithTasks(
|
||||
CreateSceneWithTasksEvent event, Emitter<CreateSceneState> emit) async {
|
||||
@ -167,9 +200,15 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
|
||||
FutureOr<void> _clearTaskList(
|
||||
ClearTaskListEvent event, Emitter<CreateSceneState> emit) {
|
||||
if (event.isAutomation == true) {
|
||||
automationTasksList.clear();
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
} else {
|
||||
tasksList.clear();
|
||||
emit(AddSceneTask(tasksList: tasksList));
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _fetchSceneTasks(
|
||||
FetchSceneTasksEvent event, Emitter<CreateSceneState> emit) async {
|
||||
@ -193,19 +232,35 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
|
||||
FutureOr<void> _clearTempTaskList(
|
||||
ClearTempTaskListEvent event, Emitter<CreateSceneState> emit) {
|
||||
if (event.isAutomation == true) {
|
||||
automationTempTasksList.clear();
|
||||
automationSelectedValues.clear();
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
} else {
|
||||
tempTasksList.clear();
|
||||
selectedValues.clear();
|
||||
emit(AddSceneTask(tasksList: tempTasksList));
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _removeFromSelectedValueById(
|
||||
RemoveFromSelectedValueById event, Emitter<CreateSceneState> emit) {
|
||||
if (event.isAutomation == true) {
|
||||
if (automationSelectedValues.containsKey(event.code)) {
|
||||
automationSelectedValues.remove(event.code);
|
||||
emit(const SelectedTaskValueState(value: null));
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
}
|
||||
} else {
|
||||
if (selectedValues.containsKey(event.code)) {
|
||||
selectedValues.remove(event.code);
|
||||
emit(const SelectedTaskValueState(value: null));
|
||||
emit(AddSceneTask(tasksList: tasksList));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _deleteScene(
|
||||
DeleteSceneEvent event, Emitter<CreateSceneState> emit) async {
|
||||
@ -226,6 +281,18 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
|
||||
FutureOr<void> _updateTaskValue(
|
||||
UpdateTaskEvent event, Emitter<CreateSceneState> emit) {
|
||||
if (event.isAutomation == true) {
|
||||
for (var i = 0; i < automationTasksList.length; i++) {
|
||||
if (automationTasksList[i].uniqueCustomId == event.taskId) {
|
||||
automationTasksList[i] = automationTasksList[i].copyWith(
|
||||
functionValue: event.newValue,
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
} else {
|
||||
for (var i = 0; i < tasksList.length; i++) {
|
||||
if (tasksList[i].uniqueCustomId == event.taskId) {
|
||||
tasksList[i] = tasksList[i].copyWith(
|
||||
@ -236,4 +303,61 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
}
|
||||
emit(AddSceneTask(tasksList: tasksList));
|
||||
}
|
||||
}
|
||||
|
||||
void addToTempAutomationTaskList(
|
||||
TempHoldSceneTasksEvent event, Emitter<CreateSceneState> emit) {
|
||||
bool updated = false;
|
||||
for (var element in automationTempTasksList) {
|
||||
if (element.code == event.deviceControlModel.code) {
|
||||
// Update the existing function with new values
|
||||
var updatedElement = element.copyWith(
|
||||
operationName: event.operation,
|
||||
deviceName: event.deviceName,
|
||||
icon: event.icon,
|
||||
code: event.deviceControlModel.code ?? '',
|
||||
deviceId: event.deviceId,
|
||||
functionValue: event.deviceControlModel.value,
|
||||
operationDialogType: event.operationType,
|
||||
operationalValues: [
|
||||
SceneOperationalValue(
|
||||
value: event.deviceControlModel.value,
|
||||
icon: '',
|
||||
),
|
||||
],
|
||||
);
|
||||
automationTempTasksList[automationTempTasksList.indexOf(element)] =
|
||||
updatedElement;
|
||||
automationSelectedValues[updatedElement.code] =
|
||||
event.deviceControlModel.value;
|
||||
updated = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!updated) {
|
||||
var newElement = SceneStaticFunction(
|
||||
operationName: event.operation,
|
||||
deviceName: event.deviceName,
|
||||
icon: event.icon,
|
||||
code: event.deviceControlModel.code ?? '',
|
||||
operationDialogType: event.operationType,
|
||||
deviceId: event.deviceId,
|
||||
functionValue: event.deviceControlModel.value,
|
||||
operationalValues: [
|
||||
SceneOperationalValue(
|
||||
value: event.deviceControlModel.value,
|
||||
icon: '',
|
||||
),
|
||||
],
|
||||
);
|
||||
automationTempTasksList.add(newElement);
|
||||
automationSelectedValues[newElement.code] =
|
||||
event.deviceControlModel.value;
|
||||
}
|
||||
emit(TempHoldSceneTask(
|
||||
tempTasksList: tempTasksList,
|
||||
automationTempTasksList: automationTempTasksList));
|
||||
emit(AddSceneTask(
|
||||
tasksList: tasksList, automationTasksList: automationTasksList));
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,6 +8,9 @@ sealed class CreateSceneEvent extends Equatable {
|
||||
}
|
||||
|
||||
class AddTaskEvent extends CreateSceneEvent {
|
||||
const AddTaskEvent({this.isAutomation});
|
||||
final bool? isAutomation;
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
@ -19,6 +22,8 @@ class TempHoldSceneTasksEvent extends CreateSceneEvent {
|
||||
final String operation;
|
||||
final String deviceName;
|
||||
final String uniqueId;
|
||||
final bool? isAutomation;
|
||||
final OperationDialogType operationType;
|
||||
|
||||
const TempHoldSceneTasksEvent({
|
||||
required this.deviceControlModel,
|
||||
@ -27,6 +32,8 @@ class TempHoldSceneTasksEvent extends CreateSceneEvent {
|
||||
required this.operation,
|
||||
required this.deviceName,
|
||||
required this.uniqueId,
|
||||
this.isAutomation,
|
||||
required this.operationType,
|
||||
});
|
||||
|
||||
@override
|
||||
@ -38,23 +45,35 @@ class TempHoldSceneTasksEvent extends CreateSceneEvent {
|
||||
operation,
|
||||
uniqueId,
|
||||
deviceName,
|
||||
icon
|
||||
icon,
|
||||
];
|
||||
}
|
||||
|
||||
class UpdateTaskEvent extends CreateSceneEvent {
|
||||
final String taskId;
|
||||
final dynamic newValue;
|
||||
const UpdateTaskEvent({required this.taskId, required this.newValue});
|
||||
final bool? isAutomation;
|
||||
const UpdateTaskEvent({
|
||||
required this.taskId,
|
||||
required this.newValue,
|
||||
this.isAutomation,
|
||||
});
|
||||
@override
|
||||
List<Object> get props => [taskId, newValue];
|
||||
}
|
||||
|
||||
class SelectedValueEvent extends CreateSceneEvent {
|
||||
final dynamic value;
|
||||
final dynamic automationValue;
|
||||
final String code;
|
||||
final bool? isAutomation;
|
||||
|
||||
const SelectedValueEvent({this.value, required this.code});
|
||||
const SelectedValueEvent({
|
||||
this.value,
|
||||
required this.code,
|
||||
this.isAutomation,
|
||||
this.automationValue,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object> get props => [value!, code];
|
||||
@ -62,8 +81,11 @@ class SelectedValueEvent extends CreateSceneEvent {
|
||||
|
||||
class RemoveTaskByIdEvent extends CreateSceneEvent {
|
||||
final String taskId;
|
||||
|
||||
const RemoveTaskByIdEvent({required this.taskId});
|
||||
final bool? isAutomation;
|
||||
const RemoveTaskByIdEvent({
|
||||
required this.taskId,
|
||||
this.isAutomation,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object> get props => [taskId];
|
||||
@ -71,7 +93,8 @@ class RemoveTaskByIdEvent extends CreateSceneEvent {
|
||||
|
||||
class RemoveTempTaskByIdEvent extends CreateSceneEvent {
|
||||
final String code;
|
||||
const RemoveTempTaskByIdEvent({required this.code});
|
||||
final bool? isAutomation;
|
||||
const RemoveTempTaskByIdEvent({required this.code, this.isAutomation});
|
||||
|
||||
@override
|
||||
List<Object> get props => [code];
|
||||
@ -79,8 +102,8 @@ class RemoveTempTaskByIdEvent extends CreateSceneEvent {
|
||||
|
||||
class RemoveFromSelectedValueById extends CreateSceneEvent {
|
||||
final String code;
|
||||
|
||||
const RemoveFromSelectedValueById({required this.code});
|
||||
final bool? isAutomation;
|
||||
const RemoveFromSelectedValueById({required this.code, this.isAutomation});
|
||||
|
||||
@override
|
||||
List<Object> get props => [code];
|
||||
@ -101,14 +124,16 @@ class CreateSceneWithTasksEvent extends CreateSceneEvent {
|
||||
}
|
||||
|
||||
class ClearTaskListEvent extends CreateSceneEvent {
|
||||
const ClearTaskListEvent();
|
||||
const ClearTaskListEvent({this.isAutomation});
|
||||
final bool? isAutomation;
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class ClearTempTaskListEvent extends CreateSceneEvent {
|
||||
const ClearTempTaskListEvent();
|
||||
const ClearTempTaskListEvent({this.isAutomation});
|
||||
final bool? isAutomation;
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
|
||||
@ -21,7 +21,8 @@ class CreateSceneError extends CreateSceneState {
|
||||
|
||||
class AddSceneTask extends CreateSceneState {
|
||||
final List<SceneStaticFunction> tasksList;
|
||||
const AddSceneTask({required this.tasksList});
|
||||
final List<SceneStaticFunction>? automationTasksList;
|
||||
const AddSceneTask({required this.tasksList, this.automationTasksList});
|
||||
|
||||
@override
|
||||
List<Object> get props => [tasksList];
|
||||
@ -29,7 +30,9 @@ class AddSceneTask extends CreateSceneState {
|
||||
|
||||
class TempHoldSceneTask extends CreateSceneState {
|
||||
final List<SceneStaticFunction> tempTasksList;
|
||||
const TempHoldSceneTask({required this.tempTasksList});
|
||||
final List<SceneStaticFunction>? automationTempTasksList;
|
||||
const TempHoldSceneTask(
|
||||
{required this.tempTasksList, this.automationTempTasksList});
|
||||
|
||||
@override
|
||||
List<Object> get props => [tempTasksList];
|
||||
|
||||
@ -89,4 +89,112 @@ class ThreeGangHelperFunctions {
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
static List<SceneStaticFunction> threeGangAutomationFunctions(
|
||||
String deviceId, String deviceName, functionValue) {
|
||||
return [
|
||||
SceneStaticFunction(
|
||||
deviceId: deviceId,
|
||||
deviceName: deviceName,
|
||||
icon: Assets.assetsAcPower,
|
||||
operationName: 'Light 1 Switch',
|
||||
code: 'switch_1',
|
||||
functionValue: functionValue,
|
||||
operationDialogType: OperationDialogType.onOff,
|
||||
operationalValues: [
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsAcPower, description: "ON", value: true),
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsAcPowerOFF, description: "OFF", value: false),
|
||||
],
|
||||
),
|
||||
SceneStaticFunction(
|
||||
deviceId: deviceId,
|
||||
deviceName: deviceName,
|
||||
icon: Assets.assetsAcPower,
|
||||
operationName: 'Light 2 Switch',
|
||||
code: 'switch_2',
|
||||
functionValue: functionValue,
|
||||
operationDialogType: OperationDialogType.onOff,
|
||||
operationalValues: [
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsAcPower, description: "ON", value: true),
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsAcPowerOFF, description: "OFF", value: false),
|
||||
],
|
||||
),
|
||||
SceneStaticFunction(
|
||||
deviceId: deviceId,
|
||||
deviceName: deviceName,
|
||||
icon: Assets.assetsAcPower,
|
||||
operationName: 'Light 3 Switch',
|
||||
code: 'switch_3',
|
||||
functionValue: functionValue,
|
||||
operationDialogType: OperationDialogType.onOff,
|
||||
operationalValues: [
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsAcPower, description: "ON", value: true),
|
||||
SceneOperationalValue(
|
||||
icon: Assets.assetsAcPowerOFF, description: "OFF", value: false),
|
||||
],
|
||||
),
|
||||
SceneStaticFunction(
|
||||
deviceId: deviceId,
|
||||
deviceName: deviceName,
|
||||
icon: Assets.assetsLightCountdown,
|
||||
operationName: 'Light 1 CountDown',
|
||||
code: 'countdown_1',
|
||||
functionValue: functionValue,
|
||||
operationDialogType: OperationDialogType.integerSteps,
|
||||
operationalValues: [
|
||||
SceneOperationalValue(
|
||||
icon: '',
|
||||
description: "sec",
|
||||
value: 0.0,
|
||||
minValue: 0,
|
||||
maxValue: 43200,
|
||||
stepValue: 1,
|
||||
),
|
||||
],
|
||||
),
|
||||
SceneStaticFunction(
|
||||
deviceId: deviceId,
|
||||
deviceName: deviceName,
|
||||
icon: Assets.assetsLightCountdown,
|
||||
operationName: 'Light 2 CountDown',
|
||||
code: 'countdown_2',
|
||||
functionValue: functionValue,
|
||||
operationDialogType: OperationDialogType.integerSteps,
|
||||
operationalValues: [
|
||||
SceneOperationalValue(
|
||||
icon: '',
|
||||
description: "sec",
|
||||
value: 0.0,
|
||||
minValue: 0,
|
||||
maxValue: 43200,
|
||||
stepValue: 1,
|
||||
),
|
||||
],
|
||||
),
|
||||
SceneStaticFunction(
|
||||
deviceId: deviceId,
|
||||
deviceName: deviceName,
|
||||
icon: Assets.assetsLightCountdown,
|
||||
operationName: 'Light 3 CountDown',
|
||||
code: 'countdown_3',
|
||||
functionValue: functionValue,
|
||||
operationDialogType: OperationDialogType.integerSteps,
|
||||
operationalValues: [
|
||||
SceneOperationalValue(
|
||||
icon: '',
|
||||
description: "sec",
|
||||
value: 0.0,
|
||||
minValue: 0,
|
||||
maxValue: 43200,
|
||||
stepValue: 1,
|
||||
),
|
||||
],
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -201,6 +201,10 @@ mixin SceneOperationsDataHelper {
|
||||
required functionValue,
|
||||
required bool isAutomation,
|
||||
}) {
|
||||
if (isAutomation) {
|
||||
return ThreeGangHelperFunctions.threeGangAutomationFunctions(
|
||||
deviceId, deviceName, functionValue);
|
||||
}
|
||||
return ThreeGangHelperFunctions.threeGangHelperFunctions(
|
||||
deviceId, deviceName, functionValue);
|
||||
}
|
||||
|
||||
@ -68,7 +68,9 @@ class CreateSceneView extends StatelessWidget {
|
||||
sceneName: '',
|
||||
),
|
||||
);
|
||||
context.read<CreateSceneBloc>().add(const ClearTaskListEvent());
|
||||
context
|
||||
.read<CreateSceneBloc>()
|
||||
.add(const ClearTaskListEvent(isAutomation: true));
|
||||
},
|
||||
),
|
||||
],
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
@ -49,7 +50,9 @@ class DeviceFunctionsView extends StatelessWidget
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
context.read<CreateSceneBloc>().add(AddTaskEvent());
|
||||
context
|
||||
.read<CreateSceneBloc>()
|
||||
.add(AddTaskEvent(isAutomation: isAutomation));
|
||||
Navigator.popUntil(context, (route) {
|
||||
return route.settings.name == Routes.sceneTasksRoute;
|
||||
});
|
||||
@ -63,6 +66,19 @@ class DeviceFunctionsView extends StatelessWidget
|
||||
],
|
||||
leading: TextButton(
|
||||
onPressed: () {
|
||||
if (isAutomation) {
|
||||
final automationSelectedValue =
|
||||
context.read<CreateSceneBloc>().automationSelectedValues;
|
||||
for (var element in device.functions) {
|
||||
if (automationSelectedValue.containsKey(element.code)) {
|
||||
context.read<CreateSceneBloc>().add(RemoveTempTaskByIdEvent(
|
||||
code: element.code!, isAutomation: true));
|
||||
context.read<CreateSceneBloc>().add(
|
||||
RemoveFromSelectedValueById(
|
||||
code: element.code!, isAutomation: true));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final selectedValue =
|
||||
context.read<CreateSceneBloc>().selectedValues;
|
||||
for (var element in device.functions) {
|
||||
@ -75,6 +91,7 @@ class DeviceFunctionsView extends StatelessWidget
|
||||
.add(RemoveFromSelectedValueById(code: element.code!));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Navigator.pop(context);
|
||||
},
|
||||
@ -130,55 +147,19 @@ class DeviceFunctionsView extends StatelessWidget
|
||||
],
|
||||
),
|
||||
onPressed: () {
|
||||
final functionValues = context
|
||||
.read<CreateSceneBloc>()
|
||||
.selectedValues[functions[index].code];
|
||||
|
||||
context.customAlertDialog(
|
||||
alertBody: getTheCorrectDialogBody(
|
||||
if (isAutomation) {
|
||||
_showAutomationDialog(
|
||||
context,
|
||||
functions[index],
|
||||
functionValues,
|
||||
),
|
||||
title: functions[index].operationName,
|
||||
onConfirm: () {
|
||||
final selectedValue = context
|
||||
.read<CreateSceneBloc>()
|
||||
.selectedValues[functions[index].code];
|
||||
if (selectedValue == null) {
|
||||
return;
|
||||
}
|
||||
context
|
||||
.read<CreateSceneBloc>()
|
||||
.add(TempHoldSceneTasksEvent(
|
||||
deviceControlModel: DeviceControlModel(
|
||||
deviceId: device.uuid,
|
||||
code: functions[index].code,
|
||||
value: selectedValue,
|
||||
),
|
||||
deviceId: device.uuid ?? '',
|
||||
operation: functions[index].operationName,
|
||||
icon: device.icon ?? '',
|
||||
deviceName: device.name ?? '',
|
||||
uniqueId: functions[index].uniqueCustomId,
|
||||
));
|
||||
Navigator.pop(context);
|
||||
},
|
||||
onDismiss: () {
|
||||
final tempTaskList =
|
||||
context.read<CreateSceneBloc>().tempTasksList;
|
||||
for (var element in tempTaskList) {
|
||||
if (element.code == functions[index].code) {
|
||||
context.read<CreateSceneBloc>().add(
|
||||
RemoveTempTaskByIdEvent(
|
||||
code: functions[index].code));
|
||||
context.read<CreateSceneBloc>().add(
|
||||
RemoveFromSelectedValueById(
|
||||
code: functions[index].code));
|
||||
}
|
||||
}
|
||||
Navigator.pop(context);
|
||||
},
|
||||
device,
|
||||
);
|
||||
} else {
|
||||
_showTabToRunDialog(
|
||||
context,
|
||||
functions[index],
|
||||
device,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
@ -194,4 +175,105 @@ class DeviceFunctionsView extends StatelessWidget
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
void _showTabToRunDialog(
|
||||
BuildContext context,
|
||||
SceneStaticFunction function,
|
||||
DeviceModel device,
|
||||
) {
|
||||
final functionValues =
|
||||
context.read<CreateSceneBloc>().selectedValues[function.code];
|
||||
|
||||
context.customAlertDialog(
|
||||
alertBody: getTheCorrectDialogBody(
|
||||
function,
|
||||
functionValues,
|
||||
),
|
||||
title: function.operationName,
|
||||
onConfirm: () {
|
||||
final selectedValue =
|
||||
context.read<CreateSceneBloc>().selectedValues[function.code];
|
||||
if (selectedValue == null) {
|
||||
return;
|
||||
}
|
||||
context.read<CreateSceneBloc>().add(TempHoldSceneTasksEvent(
|
||||
deviceControlModel: DeviceControlModel(
|
||||
deviceId: device.uuid,
|
||||
code: function.code,
|
||||
value: selectedValue,
|
||||
),
|
||||
deviceId: device.uuid ?? '',
|
||||
operation: function.operationName,
|
||||
icon: device.icon ?? '',
|
||||
deviceName: device.name ?? '',
|
||||
uniqueId: function.uniqueCustomId,
|
||||
operationType: function.operationDialogType,
|
||||
));
|
||||
Navigator.pop(context);
|
||||
},
|
||||
onDismiss: () {
|
||||
final tempTaskList = context.read<CreateSceneBloc>().tempTasksList;
|
||||
for (var element in tempTaskList) {
|
||||
if (element.code == function.code) {
|
||||
context
|
||||
.read<CreateSceneBloc>()
|
||||
.add(RemoveTempTaskByIdEvent(code: function.code));
|
||||
context
|
||||
.read<CreateSceneBloc>()
|
||||
.add(RemoveFromSelectedValueById(code: function.code));
|
||||
}
|
||||
}
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _showAutomationDialog(
|
||||
BuildContext context, SceneStaticFunction function, DeviceModel device) {
|
||||
final functionValues =
|
||||
context.read<CreateSceneBloc>().selectedValues[function.code];
|
||||
|
||||
context.customAlertDialog(
|
||||
alertBody: getTheCorrectDialogBody(
|
||||
function,
|
||||
functionValues,
|
||||
),
|
||||
title: function.operationName,
|
||||
onConfirm: () {
|
||||
final selectedValue =
|
||||
context.read<CreateSceneBloc>().selectedValues[function.code];
|
||||
if (selectedValue == null) {
|
||||
return;
|
||||
}
|
||||
context.read<CreateSceneBloc>().add(TempHoldSceneTasksEvent(
|
||||
deviceControlModel: DeviceControlModel(
|
||||
deviceId: device.uuid,
|
||||
code: function.code,
|
||||
value: selectedValue,
|
||||
),
|
||||
deviceId: device.uuid ?? '',
|
||||
operation: function.operationName,
|
||||
icon: device.icon ?? '',
|
||||
deviceName: device.name ?? '',
|
||||
uniqueId: function.uniqueCustomId,
|
||||
operationType: function.operationDialogType,
|
||||
));
|
||||
Navigator.pop(context);
|
||||
},
|
||||
onDismiss: () {
|
||||
final tempTaskList = context.read<CreateSceneBloc>().tempTasksList;
|
||||
for (var element in tempTaskList) {
|
||||
if (element.code == function.code) {
|
||||
context
|
||||
.read<CreateSceneBloc>()
|
||||
.add(RemoveTempTaskByIdEvent(code: function.code));
|
||||
context
|
||||
.read<CreateSceneBloc>()
|
||||
.add(RemoveFromSelectedValueById(code: function.code));
|
||||
}
|
||||
}
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,6 +26,7 @@ class _AlertDialogCountdownState extends State<AlertDialogCountdown> {
|
||||
@override
|
||||
didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
|
||||
final tempTaskList = context.read<CreateSceneBloc>().tempTasksList;
|
||||
|
||||
for (var element in tempTaskList) {
|
||||
|
||||
@ -26,6 +26,7 @@ class _AlertDialogFunctionsOperationsBodyState
|
||||
@override
|
||||
didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
|
||||
final tempTaskList = context.read<CreateSceneBloc>().tempTasksList;
|
||||
|
||||
if (tempTaskList.isNotEmpty) {
|
||||
|
||||
@ -2,9 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
|
||||
import 'package:syncrow_app/features/scene/model/scene_static_function.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/title_medium.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/title_small.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
|
||||
@ -125,8 +125,9 @@ class CustomBottomSheetWidget extends StatelessWidget {
|
||||
icon: Assets.delay,
|
||||
deviceName: 'Delay The Action',
|
||||
uniqueId: functions[0].uniqueCustomId,
|
||||
operationType: functions[0].operationDialogType,
|
||||
));
|
||||
context.read<CreateSceneBloc>().add(AddTaskEvent());
|
||||
context.read<CreateSceneBloc>().add(const AddTaskEvent());
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
|
||||
@ -4,6 +4,7 @@ import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
|
||||
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
|
||||
import 'package:syncrow_app/features/scene/model/scene_settings_route_arguments.dart';
|
||||
import 'package:syncrow_app/features/scene/widgets/if_then_containers/then_added_tasks.dart';
|
||||
import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/light_divider.dart';
|
||||
@ -60,29 +61,23 @@ class IFDefaultContainer extends StatelessWidget {
|
||||
return const Center(child: LinearProgressIndicator());
|
||||
}
|
||||
|
||||
// if (state is AddSceneTask) {
|
||||
// final taskLists = state.tasksList;
|
||||
// if (taskLists.isNotEmpty) {
|
||||
// return ListView.builder(
|
||||
// shrinkWrap: true,
|
||||
// physics: const NeverScrollableScrollPhysics(),
|
||||
// itemCount: taskLists.length,
|
||||
// reverse: true,
|
||||
// itemBuilder: (context, index) {
|
||||
// return ThenAddedTasksContainer(
|
||||
// taskItem: taskLists[index],
|
||||
// );
|
||||
// },
|
||||
// );
|
||||
// }
|
||||
// return SceneListTile(
|
||||
// titleString: '+ Add Task',
|
||||
// textAlign: TextAlign.center,
|
||||
// onPressed: () => context.customBottomSheet(
|
||||
// child: const CustomBottomSheetWidget(),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
if (state is AddSceneTask) {
|
||||
final automationTasksList = state.automationTasksList;
|
||||
if (automationTasksList?.isNotEmpty == true) {
|
||||
return ListView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: automationTasksList?.length,
|
||||
reverse: true,
|
||||
itemBuilder: (context, index) {
|
||||
return ThenAddedTasksContainer(
|
||||
taskItem: automationTasksList![index],
|
||||
isAutomation: true,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
return SceneListTile(
|
||||
titleString: '+ Add Condition',
|
||||
textAlign: TextAlign.center,
|
||||
|
||||
@ -22,11 +22,13 @@ class ThenAddedTasksContainer extends StatelessWidget
|
||||
required this.taskItem,
|
||||
this.sceneId,
|
||||
this.index,
|
||||
this.isAutomation,
|
||||
});
|
||||
|
||||
final SceneStaticFunction taskItem;
|
||||
String? sceneId;
|
||||
int? index;
|
||||
bool? isAutomation;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -68,6 +70,22 @@ class ThenAddedTasksContainer extends StatelessWidget
|
||||
final savedCode = functionOperation.first.deviceId.contains('delay')
|
||||
? 'delay'
|
||||
: functionOperation.first.code;
|
||||
if (isAutomation == true) {
|
||||
final automationSelectedValue =
|
||||
createSceneBloc.automationSelectedValues[savedCode];
|
||||
|
||||
try {
|
||||
createSceneBloc.add(
|
||||
UpdateTaskEvent(
|
||||
newValue: automationSelectedValue,
|
||||
taskId: taskItem.uniqueCustomId,
|
||||
isAutomation: true,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
debugPrint('Error adding UpdateTaskEvent: $e');
|
||||
}
|
||||
} else {
|
||||
final selectedValue = createSceneBloc.selectedValues[savedCode];
|
||||
|
||||
try {
|
||||
@ -80,6 +98,8 @@ class ThenAddedTasksContainer extends StatelessWidget
|
||||
} catch (e) {
|
||||
debugPrint('Error adding UpdateTaskEvent: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
@ -109,9 +129,16 @@ class ThenAddedTasksContainer extends StatelessWidget
|
||||
onDismissed: (direction) {
|
||||
String removeFunctionById = taskItem.uniqueCustomId;
|
||||
|
||||
context
|
||||
.read<CreateSceneBloc>()
|
||||
.add(RemoveTaskByIdEvent(taskId: removeFunctionById));
|
||||
if (isAutomation == true) {
|
||||
context.read<CreateSceneBloc>().add(RemoveTaskByIdEvent(
|
||||
taskId: removeFunctionById,
|
||||
isAutomation: true,
|
||||
));
|
||||
} else {
|
||||
context.read<CreateSceneBloc>().add(RemoveTaskByIdEvent(
|
||||
taskId: removeFunctionById,
|
||||
));
|
||||
}
|
||||
|
||||
String removeFunction =
|
||||
"${taskItem.operationName} with value ${taskItem.operationalValues.first.value}";
|
||||
|
||||
Reference in New Issue
Block a user