mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-11-27 18:34:56 +00:00
fixed autoamtion update
This commit is contained in:
@ -7,100 +7,106 @@ import 'package:syncrow_web/pages/routiens/widgets/dialog_header.dart';
|
||||
import 'package:syncrow_web/pages/routiens/widgets/dialog_footer.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
|
||||
class AutomationDialog extends StatelessWidget {
|
||||
class AutomationDialog extends StatefulWidget {
|
||||
final String automationName;
|
||||
final String automationId;
|
||||
final String uniqueCustomId;
|
||||
final String? passedAutomationActionExecutor;
|
||||
|
||||
const AutomationDialog({
|
||||
super.key,
|
||||
required this.automationName,
|
||||
required this.automationId,
|
||||
required this.uniqueCustomId,
|
||||
this.passedAutomationActionExecutor,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<RoutineBloc, RoutineState>(
|
||||
builder: (context, state) {
|
||||
final String? initialSelection = state.automationActionExecutor;
|
||||
State<AutomationDialog> createState() => _AutomationDialogState();
|
||||
}
|
||||
|
||||
return Dialog(
|
||||
shape:
|
||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: Container(
|
||||
width: 400,
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
DialogHeader(automationName),
|
||||
const SizedBox(height: 16),
|
||||
ListTile(
|
||||
leading:
|
||||
SvgPicture.asset(Assets.acPower, width: 24, height: 24),
|
||||
title: const Text('Enable'),
|
||||
trailing: Radio<String?>(
|
||||
value: 'rule_enable',
|
||||
groupValue: initialSelection,
|
||||
onChanged: (String? value) {
|
||||
if (value != null) {
|
||||
context.read<RoutineBloc>().add(
|
||||
SetAutomationActionExecutor(
|
||||
automationActionExecutor: value,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
leading: SvgPicture.asset(Assets.acPowerOff,
|
||||
width: 24, height: 24),
|
||||
title: const Text('Disable'),
|
||||
trailing: Radio<String?>(
|
||||
value: 'rule_disable',
|
||||
groupValue: initialSelection,
|
||||
onChanged: (String? value) {
|
||||
if (value != null) {
|
||||
context.read<RoutineBloc>().add(
|
||||
SetAutomationActionExecutor(
|
||||
automationActionExecutor: value,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
DialogFooter(
|
||||
onConfirm: () {
|
||||
if (state.automationActionExecutor != null) {
|
||||
context.read<RoutineBloc>().add(
|
||||
AddFunctionToRoutine(
|
||||
[
|
||||
DeviceFunctionData(
|
||||
entityId: automationId,
|
||||
functionCode: 'automation',
|
||||
value: state.automationActionExecutor,
|
||||
operationName: 'Automation',
|
||||
),
|
||||
],
|
||||
uniqueCustomId,
|
||||
),
|
||||
);
|
||||
Navigator.of(context).pop(true);
|
||||
}
|
||||
},
|
||||
onCancel: () => Navigator.of(context).pop(false),
|
||||
isConfirmEnabled: state.automationActionExecutor != null,
|
||||
dialogWidth: 400,
|
||||
),
|
||||
],
|
||||
class _AutomationDialogState extends State<AutomationDialog> {
|
||||
String? selectedAutomationActionExecutor;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
List<DeviceFunctionData>? functions = context
|
||||
.read<RoutineBloc>()
|
||||
.state
|
||||
.selectedFunctions[widget.uniqueCustomId];
|
||||
for (DeviceFunctionData data in functions ?? []) {
|
||||
if (data.entityId == widget.automationId) {
|
||||
selectedAutomationActionExecutor = data.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Dialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: Container(
|
||||
width: 400,
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
DialogHeader(widget.automationName),
|
||||
const SizedBox(height: 16),
|
||||
ListTile(
|
||||
leading: SvgPicture.asset(Assets.acPower, width: 24, height: 24),
|
||||
title: const Text('Enable'),
|
||||
trailing: Radio<String?>(
|
||||
value: 'rule_enable',
|
||||
groupValue: selectedAutomationActionExecutor,
|
||||
onChanged: (String? value) {
|
||||
setState(() {
|
||||
selectedAutomationActionExecutor = 'rule_enable';
|
||||
});
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
ListTile(
|
||||
leading:
|
||||
SvgPicture.asset(Assets.acPowerOff, width: 24, height: 24),
|
||||
title: const Text('Disable'),
|
||||
trailing: Radio<String?>(
|
||||
value: 'rule_disable',
|
||||
groupValue: selectedAutomationActionExecutor,
|
||||
onChanged: (String? value) {
|
||||
setState(() {
|
||||
selectedAutomationActionExecutor = 'rule_disable';
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
DialogFooter(
|
||||
onConfirm: () {
|
||||
if (selectedAutomationActionExecutor != null) {
|
||||
context.read<RoutineBloc>().add(
|
||||
AddFunctionToRoutine(
|
||||
[
|
||||
DeviceFunctionData(
|
||||
entityId: widget.automationId,
|
||||
functionCode: 'automation',
|
||||
value: selectedAutomationActionExecutor,
|
||||
operationName: 'Automation',
|
||||
),
|
||||
],
|
||||
widget.uniqueCustomId,
|
||||
),
|
||||
);
|
||||
}
|
||||
Navigator.of(context).pop(true);
|
||||
},
|
||||
onCancel: () => Navigator.of(context).pop(),
|
||||
isConfirmEnabled: selectedAutomationActionExecutor != null,
|
||||
dialogWidth: 400,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,8 +87,11 @@ class ThenContainer extends StatelessWidget {
|
||||
...state.thenItems[index],
|
||||
'imagePath':
|
||||
Assets.automation,
|
||||
'title': state
|
||||
.thenItems[index]['name'],
|
||||
'title':
|
||||
state.thenItems[index]
|
||||
['name'] ??
|
||||
state.thenItems[index]
|
||||
['title'],
|
||||
}));
|
||||
}
|
||||
return;
|
||||
@ -171,7 +174,7 @@ class ThenContainer extends StatelessWidget {
|
||||
if (mutableData['type'] == 'tap_to_run' && state.isAutomation) {
|
||||
context.read<RoutineBloc>().add(AddToThenContainer({
|
||||
...mutableData,
|
||||
'imagePath': Assets.logo,
|
||||
'imagePath': mutableData['imagePath'] ?? Assets.logo,
|
||||
'title': mutableData['name'],
|
||||
}));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user