mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
107 lines
4.0 KiB
Dart
107 lines
4.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart';
|
|
import 'package:syncrow_web/pages/routiens/models/device_functions.dart';
|
|
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 {
|
|
final String automationName;
|
|
final String automationId;
|
|
final String uniqueCustomId;
|
|
|
|
const AutomationDialog({
|
|
super.key,
|
|
required this.automationName,
|
|
required this.automationId,
|
|
required this.uniqueCustomId,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocBuilder<RoutineBloc, RoutineState>(
|
|
builder: (context, state) {
|
|
final String? initialSelection = state.automationActionExecutor;
|
|
|
|
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,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|