mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-11-27 16:34:56 +00:00
push tab to run and handling automation
This commit is contained in:
@ -11,6 +11,9 @@ class DraggableCard extends StatelessWidget {
|
||||
final String title;
|
||||
final Map<String, dynamic> deviceData;
|
||||
final EdgeInsetsGeometry? padding;
|
||||
final void Function()? onRemove;
|
||||
final bool? isFromThen;
|
||||
final bool? isFromIf;
|
||||
|
||||
const DraggableCard({
|
||||
super.key,
|
||||
@ -18,6 +21,9 @@ class DraggableCard extends StatelessWidget {
|
||||
required this.title,
|
||||
required this.deviceData,
|
||||
this.padding,
|
||||
this.onRemove,
|
||||
this.isFromThen,
|
||||
this.isFromIf,
|
||||
});
|
||||
|
||||
@override
|
||||
@ -44,75 +50,97 @@ class DraggableCard extends StatelessWidget {
|
||||
Widget _buildCardContent(
|
||||
BuildContext context, List<DeviceFunctionData> deviceFunctions,
|
||||
{EdgeInsetsGeometry? padding}) {
|
||||
return Card(
|
||||
color: ColorsManager.whiteColors,
|
||||
child: Container(
|
||||
padding: padding ?? const EdgeInsets.all(16),
|
||||
width: 110,
|
||||
height: deviceFunctions.isEmpty ? 123 : null,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Column(
|
||||
return Stack(
|
||||
children: [
|
||||
Card(
|
||||
color: ColorsManager.whiteColors,
|
||||
child: Container(
|
||||
padding: padding ?? const EdgeInsets.all(16),
|
||||
width: 110,
|
||||
height: deviceFunctions.isEmpty ? 123 : null,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
height: 50,
|
||||
width: 50,
|
||||
decoration: BoxDecoration(
|
||||
color: ColorsManager.CircleImageBackground,
|
||||
borderRadius: BorderRadius.circular(90),
|
||||
border: Border.all(
|
||||
color: ColorsManager.graysColor,
|
||||
),
|
||||
),
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: imagePath.contains('.svg')
|
||||
? SvgPicture.asset(
|
||||
imagePath,
|
||||
)
|
||||
: Image.network(imagePath),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 3),
|
||||
child: Text(
|
||||
title,
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 2,
|
||||
style: context.textTheme.bodySmall?.copyWith(
|
||||
color: ColorsManager.blackColor,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (deviceFunctions.isNotEmpty)
|
||||
// const Divider(height: 1),
|
||||
...deviceFunctions.map((function) => Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
'${function.operationName}: ${function.value}',
|
||||
style: context.textTheme.bodySmall?.copyWith(
|
||||
fontSize: 9,
|
||||
color: ColorsManager.textGray,
|
||||
height: 1.2,
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
height: 50,
|
||||
width: 50,
|
||||
decoration: BoxDecoration(
|
||||
color: ColorsManager.CircleImageBackground,
|
||||
borderRadius: BorderRadius.circular(90),
|
||||
border: Border.all(
|
||||
color: ColorsManager.graysColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
)),
|
||||
],
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: imagePath.contains('.svg')
|
||||
? SvgPicture.asset(
|
||||
imagePath,
|
||||
)
|
||||
: Image.network(imagePath),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 3),
|
||||
child: Text(
|
||||
title,
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 2,
|
||||
style: context.textTheme.bodySmall?.copyWith(
|
||||
color: ColorsManager.blackColor,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (deviceFunctions.isNotEmpty)
|
||||
// const Divider(height: 1),
|
||||
...deviceFunctions.map((function) => Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
'${function.operationName}: ${function.value}',
|
||||
style: context.textTheme.bodySmall?.copyWith(
|
||||
fontSize: 9,
|
||||
color: ColorsManager.textGray,
|
||||
height: 1.2,
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
top: -4,
|
||||
right: -6,
|
||||
child: Visibility(
|
||||
visible: (isFromIf ?? false) || (isFromThen ?? false),
|
||||
child: IconButton(
|
||||
onPressed: onRemove == null
|
||||
? null
|
||||
: () {
|
||||
onRemove!();
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.close,
|
||||
color: ColorsManager.boxColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,6 +43,7 @@ class RoutineSearchAndButtons extends StatelessWidget {
|
||||
boxDecoration: containerWhiteDecoration,
|
||||
elevation: 0,
|
||||
borderRadius: 15,
|
||||
isRequired: true,
|
||||
width: 450,
|
||||
onChanged: (value) {
|
||||
context
|
||||
@ -61,10 +62,8 @@ class RoutineSearchAndButtons extends StatelessWidget {
|
||||
onPressed: () async {
|
||||
final result =
|
||||
await SettingHelper.showSettingDialog(
|
||||
context: context,
|
||||
isAutomation: context
|
||||
.read<RoutineBloc>()
|
||||
.isAutomation);
|
||||
context: context,
|
||||
);
|
||||
if (result != null) {
|
||||
context
|
||||
.read<RoutineBloc>()
|
||||
|
||||
@ -30,19 +30,25 @@ class ThenContainer extends StatelessWidget {
|
||||
fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 16),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: state.thenItems
|
||||
.map((item) => DraggableCard(
|
||||
// key: Key(item['key']!),
|
||||
imagePath: item['imagePath']!,
|
||||
title: item['title']!,
|
||||
deviceData: item,
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 4, vertical: 8),
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: List.generate(
|
||||
state.thenItems.length,
|
||||
(index) => DraggableCard(
|
||||
imagePath:
|
||||
state.thenItems[index]['imagePath'] ?? '',
|
||||
title: state.thenItems[index]['title'] ?? '',
|
||||
deviceData: state.thenItems[index],
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 4, vertical: 8),
|
||||
isFromThen: true,
|
||||
isFromIf: false,
|
||||
onRemove: () {
|
||||
context.read<RoutineBloc>().add(
|
||||
RemoveDragCard(
|
||||
index: index, isFromThen: true));
|
||||
},
|
||||
))),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user