mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
122 lines
4.9 KiB
Dart
122 lines
4.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
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/constants/assets.dart';
|
|
import 'package:uuid/uuid.dart';
|
|
|
|
class IfContainer extends StatelessWidget {
|
|
const IfContainer({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocBuilder<RoutineBloc, RoutineState>(
|
|
builder: (context, state) {
|
|
return DragTarget<Map<String, dynamic>>(
|
|
builder: (context, candidateData, rejectedData) {
|
|
return Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Text('IF',
|
|
style:
|
|
TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
|
const SizedBox(height: 16),
|
|
if (context.read<RoutineBloc>().isTabToRun)
|
|
const Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
DraggableCard(
|
|
imagePath: Assets.tabToRun,
|
|
title: 'Tab to run',
|
|
deviceData: {},
|
|
),
|
|
],
|
|
),
|
|
if (!context.read<RoutineBloc>().isTabToRun)
|
|
Wrap(
|
|
spacing: 8,
|
|
runSpacing: 8,
|
|
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));
|
|
},
|
|
)),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
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 (mutableData['deviceId'] == 'tab_to_run') {
|
|
context
|
|
.read<RoutineBloc>()
|
|
.add(AddToIfContainer(mutableData, 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(mutableData['productType'])) {
|
|
context
|
|
.read<RoutineBloc>()
|
|
.add(AddToIfContainer(mutableData, false));
|
|
}
|
|
}
|
|
}
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|