mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-25 16:27:55 +00:00
fixed automation bugs
This commit is contained in:
@@ -29,41 +29,51 @@ class _AlertDialogSliderStepsState extends State<AlertDialogSliderSteps> {
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
final createSceneBloc = context.read<CreateSceneBloc>();
|
||||
|
||||
if (widget.isAutomation) {
|
||||
final automationTempTaskList =
|
||||
context.read<CreateSceneBloc>().automationTempTasksList;
|
||||
final automationTempTaskList = createSceneBloc.automationTempTasksList;
|
||||
final automationComparatorValues =
|
||||
context.read<CreateSceneBloc>().automationComparatorValues;
|
||||
createSceneBloc.automationComparatorValues;
|
||||
|
||||
if (automationTempTaskList.isNotEmpty) {
|
||||
for (var element in automationTempTaskList) {
|
||||
if (element.code == widget.taskItem.code) {
|
||||
groupValue = element.functionValue;
|
||||
selectedToggleIndex =
|
||||
_comparatorToIndex(automationComparatorValues[element.code]);
|
||||
}
|
||||
for (var element in automationTempTaskList) {
|
||||
if (element.code == widget.taskItem.code) {
|
||||
groupValue = element.functionValue;
|
||||
selectedToggleIndex =
|
||||
_comparatorToIndex(automationComparatorValues[element.code]);
|
||||
}
|
||||
}
|
||||
if (widget.functionValue != null) {
|
||||
groupValue = widget.functionValue;
|
||||
} else {
|
||||
groupValue = widget.taskItem.operationalValues[0].minValue;
|
||||
}
|
||||
if (widget.taskItem.comparator != null) {
|
||||
selectedToggleIndex = _comparatorToIndex(widget.taskItem.comparator);
|
||||
}
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
if (widget.functionValue != null) {
|
||||
groupValue = _normalizeValue(widget.functionValue);
|
||||
} else {
|
||||
groupValue =
|
||||
_normalizeValue(widget.taskItem.operationalValues[0].minValue);
|
||||
}
|
||||
|
||||
if (widget.taskItem.comparator != null) {
|
||||
selectedToggleIndex = _comparatorToIndex(widget.taskItem.comparator);
|
||||
}
|
||||
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
double _normalizeValue(dynamic value) {
|
||||
if (widget.taskItem.code == "temp_set" ||
|
||||
widget.taskItem.code == "temp_current") {
|
||||
return (value as double) / 10;
|
||||
}
|
||||
return value.toDouble();
|
||||
}
|
||||
|
||||
int _comparatorToIndex(String? comparator) {
|
||||
switch (comparator) {
|
||||
case "<=":
|
||||
case "<":
|
||||
return 0;
|
||||
case "==":
|
||||
return 1;
|
||||
case ">=":
|
||||
case ">":
|
||||
return 2;
|
||||
default:
|
||||
return 1;
|
||||
@@ -73,11 +83,11 @@ class _AlertDialogSliderStepsState extends State<AlertDialogSliderSteps> {
|
||||
String _indexToComparator(int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return "<=";
|
||||
return "<";
|
||||
case 1:
|
||||
return "==";
|
||||
case 2:
|
||||
return ">=";
|
||||
return ">";
|
||||
default:
|
||||
return "==";
|
||||
}
|
||||
@@ -98,10 +108,14 @@ class _AlertDialogSliderStepsState extends State<AlertDialogSliderSteps> {
|
||||
setState(() {
|
||||
selectedToggleIndex = index;
|
||||
});
|
||||
context.read<CreateSceneBloc>().add(SelectedValueEvent(
|
||||
code: widget.taskItem.code,
|
||||
isAutomation: widget.isAutomation,
|
||||
comparator: _indexToComparator(selectedToggleIndex)));
|
||||
context.read<CreateSceneBloc>().add(
|
||||
SelectedValueEvent(
|
||||
value: _deNormalizeValue(groupValue),
|
||||
code: widget.taskItem.code,
|
||||
isAutomation: widget.isAutomation,
|
||||
comparator: _indexToComparator(selectedToggleIndex),
|
||||
),
|
||||
);
|
||||
},
|
||||
borderRadius: BorderRadius.circular(30),
|
||||
selectedColor: Colors.white,
|
||||
@@ -181,8 +195,8 @@ class _AlertDialogSliderStepsState extends State<AlertDialogSliderSteps> {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
child: Slider(
|
||||
value: groupValue ?? 0,
|
||||
min: operation.minValue?.toDouble() ?? 0,
|
||||
max: operation.maxValue?.toDouble() ?? 0,
|
||||
min: operation.minValue ?? 0,
|
||||
max: operation.maxValue ?? 0,
|
||||
inactiveColor: ColorsManager.primaryColorWithOpacity
|
||||
.withOpacity(0.2),
|
||||
divisions: operation.stepValue != null
|
||||
@@ -193,10 +207,10 @@ class _AlertDialogSliderStepsState extends State<AlertDialogSliderSteps> {
|
||||
: null,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
groupValue = value.round().toDouble();
|
||||
groupValue = value;
|
||||
});
|
||||
context.read<CreateSceneBloc>().add(SelectedValueEvent(
|
||||
value: groupValue,
|
||||
value: _deNormalizeValue(groupValue),
|
||||
code: widget.taskItem.code,
|
||||
isAutomation: widget.isAutomation,
|
||||
comparator:
|
||||
@@ -213,4 +227,12 @@ class _AlertDialogSliderStepsState extends State<AlertDialogSliderSteps> {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
double _deNormalizeValue(double? value) {
|
||||
if (widget.taskItem.code == "temp_set" ||
|
||||
widget.taskItem.code == "temp_current") {
|
||||
return (value ?? 0) * 10;
|
||||
}
|
||||
return value ?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user