push tab to run and handling automation

This commit is contained in:
ashrafzarkanisala
2024-11-24 23:07:03 +03:00
parent 87c47a74ce
commit 0c555cda83
13 changed files with 295 additions and 154 deletions

View File

@ -4,6 +4,7 @@ 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/constants/assets.dart';
import 'package:uuid/uuid.dart';
class IfContainer extends StatelessWidget {
const IfContainer({super.key});
@ -20,7 +21,9 @@ class IfContainer extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('IF', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
const Text('IF',
style:
TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
const SizedBox(height: 16),
if (context.read<RoutineBloc>().isTabToRun)
const Row(
@ -37,14 +40,23 @@ class IfContainer extends StatelessWidget {
Wrap(
spacing: 8,
runSpacing: 8,
children: state.ifItems
.map((item) => DraggableCard(
// key: Key(item['key']!),
imagePath: item['imagePath'] ?? '',
title: item['title'] ?? 'Tab to run',
deviceData: item,
))
.toList(),
children: List.generate(
state.ifItems.length,
(index) => DraggableCard(
imagePath:
state.ifItems[index]['imagePath'] ?? '',
title: state.ifItems[index]['title'] ?? '',
deviceData: state.ifItems[index],
padding: const EdgeInsets.symmetric(
horizontal: 4, vertical: 8),
isFromThen: false,
isFromIf: true,
onRemove: () {
context.read<RoutineBloc>().add(
RemoveDragCard(
index: index, isFromThen: false));
},
)),
),
],
),
@ -52,15 +64,52 @@ 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 (data['deviceId'] == 'tab_to_run') {
context.read<RoutineBloc>().add(AddToIfContainer(data, true));
if (mutableData['deviceId'] == 'tab_to_run') {
context
.read<RoutineBloc>()
.add(AddToIfContainer(mutableData, true));
} else {
final result = await DeviceDialogHelper.showDeviceDialog(context, data);
final result = await DeviceDialogHelper.showDeviceDialog(
context, mutableData);
if (result != null) {
context.read<RoutineBloc>().add(AddToIfContainer(result, false));
} else if (!['AC', '1G', '2G', '3G'].contains(data['productType'])) {
context.read<RoutineBloc>().add(AddToIfContainer(data, false));
context
.read<RoutineBloc>()
.add(AddToIfContainer(mutableData, false));
} else if (!['AC', '1G', '2G', '3G']
.contains(mutableData['productType'])) {
context
.read<RoutineBloc>()
.add(AddToIfContainer(mutableData, false));
}
}
}