mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-16 01:56:24 +00:00
working on automation
This commit is contained in:
@ -3,7 +3,9 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart';
|
||||
import 'package:syncrow_web/pages/routiens/helper/dialog_helper/device_dialog_helper.dart';
|
||||
import 'package:syncrow_web/pages/routiens/widgets/dragable_card.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class IfContainer extends StatelessWidget {
|
||||
@ -21,11 +23,19 @@ class IfContainer extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('IF',
|
||||
style:
|
||||
TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text('IF',
|
||||
style: TextStyle(
|
||||
fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
if (state.isAutomation)
|
||||
AutomationOperatorSelector(
|
||||
selectedOperator: state.selectedAutomationOperator),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (context.read<RoutineBloc>().isTabToRun)
|
||||
if (state.isTabToRun)
|
||||
const Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
@ -36,7 +46,7 @@ class IfContainer extends StatelessWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
if (!context.read<RoutineBloc>().isTabToRun)
|
||||
if (!state.isTabToRun)
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
@ -64,35 +74,12 @@ class IfContainer extends StatelessWidget {
|
||||
},
|
||||
onWillAccept: (data) => data != null,
|
||||
onAccept: (data) async {
|
||||
// final uniqueCustomId = const Uuid().v4();
|
||||
|
||||
// final mutableData = Map<String, dynamic>.from(data);
|
||||
// mutableData['uniqueCustomId'] = uniqueCustomId;
|
||||
|
||||
// if (!context.read<RoutineBloc>().isTabToRun) {
|
||||
// if (data['deviceId'] == 'tab_to_run') {
|
||||
// context.read<RoutineBloc>().add(AddToIfContainer(data, true));
|
||||
// } else {
|
||||
// final result =
|
||||
// await DeviceDialogHelper.showDeviceDialog(context, mutableData);
|
||||
// if (result != null) {
|
||||
// context
|
||||
// .read<RoutineBloc>()
|
||||
// .add(AddToIfContainer(mutableData, false));
|
||||
// } else if (!['AC', '1G', '2G', '3G']
|
||||
// .contains(data['productType'])) {
|
||||
// context
|
||||
// .read<RoutineBloc>()
|
||||
// .add(AddToIfContainer(mutableData, false));
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
final uniqueCustomId = const Uuid().v4();
|
||||
|
||||
final mutableData = Map<String, dynamic>.from(data);
|
||||
mutableData['uniqueCustomId'] = uniqueCustomId;
|
||||
|
||||
if (!context.read<RoutineBloc>().isTabToRun) {
|
||||
if (!state.isTabToRun) {
|
||||
if (mutableData['deviceId'] == 'tab_to_run') {
|
||||
context
|
||||
.read<RoutineBloc>()
|
||||
@ -119,3 +106,77 @@ class IfContainer extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class AutomationOperatorSelector extends StatelessWidget {
|
||||
const AutomationOperatorSelector({
|
||||
super.key,
|
||||
required this.selectedOperator,
|
||||
});
|
||||
|
||||
final String selectedOperator;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: ColorsManager.dividerColor),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(
|
||||
backgroundColor: selectedOperator == 'and'
|
||||
? ColorsManager.dialogBlueTitle
|
||||
: ColorsManager.whiteColors,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(0),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
'All condition is met',
|
||||
style: context.textTheme.bodyMedium?.copyWith(
|
||||
color: selectedOperator == 'and'
|
||||
? ColorsManager.whiteColors
|
||||
: ColorsManager.blackColor,
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
context
|
||||
.read<RoutineBloc>()
|
||||
.add(const ChangeAutomationOperator(operator: 'and'));
|
||||
},
|
||||
),
|
||||
Container(
|
||||
width: 3,
|
||||
height: 24,
|
||||
color: ColorsManager.dividerColor,
|
||||
),
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(
|
||||
backgroundColor: selectedOperator == 'or'
|
||||
? ColorsManager.dialogBlueTitle
|
||||
: ColorsManager.whiteColors,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(0),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
'Any condition is met',
|
||||
style: context.textTheme.bodyMedium?.copyWith(
|
||||
color: selectedOperator == 'or'
|
||||
? ColorsManager.whiteColors
|
||||
: ColorsManager.blackColor,
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
context
|
||||
.read<RoutineBloc>()
|
||||
.add(const ChangeAutomationOperator(operator: 'or'));
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user