mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
Implemented update card functionlity
This commit is contained in:
@ -44,8 +44,19 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
}
|
||||
|
||||
void _onAddToThenContainer(AddToThenContainer event, Emitter<RoutineState> emit) {
|
||||
final updatedThenItems = List<Map<String, dynamic>>.from(state.thenItems)..add(event.item);
|
||||
emit(state.copyWith(thenItems: updatedThenItems));
|
||||
final currentItems = List<Map<String, dynamic>>.from(state.thenItems);
|
||||
|
||||
// Find the index of the item in teh current itemsList
|
||||
int index =
|
||||
currentItems.indexWhere((map) => map['uniqueCustomId'] == event.item['uniqueCustomId']);
|
||||
// Replace the map if the index is valid
|
||||
if (index != -1) {
|
||||
currentItems[index] = event.item;
|
||||
} else {
|
||||
currentItems.add(event.item);
|
||||
}
|
||||
|
||||
emit(state.copyWith(thenItems: currentItems));
|
||||
}
|
||||
|
||||
void _onAddFunctionsToRoutine(AddFunctionToRoutine event, Emitter<RoutineState> emit) {
|
||||
|
@ -8,13 +8,25 @@ import 'package:syncrow_web/pages/routiens/widgets/dialog_header.dart';
|
||||
|
||||
class DelayHelper {
|
||||
static Future<Map<String, dynamic>?> showDelayPickerDialog(
|
||||
BuildContext context, String uniqueCustomId) async {
|
||||
BuildContext context, Map<String, dynamic> data) async {
|
||||
int hours = 0;
|
||||
int minutes = 0;
|
||||
|
||||
return showDialog<Map<String, dynamic>?>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
final routineBloc = context.read<RoutineBloc>();
|
||||
int totalSec = 0;
|
||||
|
||||
final selectedFunctionData =
|
||||
routineBloc.state.selectedFunctions[data['uniqueCustomId']] ?? [];
|
||||
|
||||
if (selectedFunctionData.isNotEmpty) {
|
||||
totalSec = selectedFunctionData[0].value;
|
||||
// Convert seconds to hours and minutes
|
||||
hours = totalSec ~/ 3600;
|
||||
minutes = (totalSec % 3600) ~/ 60;
|
||||
}
|
||||
return AlertDialog(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
content: Container(
|
||||
@ -31,8 +43,7 @@ class DelayHelper {
|
||||
Expanded(
|
||||
child: CupertinoTimerPicker(
|
||||
mode: CupertinoTimerPickerMode.hm,
|
||||
initialTimerDuration:
|
||||
Duration(hours: hours, minutes: minutes),
|
||||
initialTimerDuration: Duration(hours: hours, minutes: minutes),
|
||||
onTimerDurationChanged: (Duration newDuration) {
|
||||
hours = newDuration.inHours;
|
||||
minutes = newDuration.inMinutes % 60;
|
||||
@ -54,7 +65,7 @@ class DelayHelper {
|
||||
value: totalSeconds,
|
||||
)
|
||||
],
|
||||
uniqueCustomId,
|
||||
data['uniqueCustomId'],
|
||||
));
|
||||
|
||||
Navigator.pop(context, {
|
||||
|
@ -34,11 +34,9 @@ class _ScenesAndAutomationsState extends State<ScenesAndAutomations> {
|
||||
children: scenes.asMap().entries.map((entry) {
|
||||
final scene = entry.value;
|
||||
if (state.searchText != null && state.searchText!.isNotEmpty) {
|
||||
return scene.name
|
||||
.toLowerCase()
|
||||
.contains(state.searchText!.toLowerCase())
|
||||
return scene.name.toLowerCase().contains(state.searchText!.toLowerCase())
|
||||
? DraggableCard(
|
||||
imagePath: Assets.logo,
|
||||
imagePath: scene.icon ?? Assets.loginLogo,
|
||||
title: scene.name,
|
||||
deviceData: {
|
||||
'deviceId': scene.id,
|
||||
|
@ -25,45 +25,73 @@ class ThenContainer extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('THEN',
|
||||
style: TextStyle(
|
||||
fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
const Text('THEN', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 16),
|
||||
Wrap(
|
||||
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));
|
||||
(index) => GestureDetector(
|
||||
onTap: () async {
|
||||
if (state.thenItems[index]['deviceId'] == 'delay') {
|
||||
final result = await DelayHelper.showDelayPickerDialog(
|
||||
context, state.thenItems[index]);
|
||||
|
||||
if (result != null) {
|
||||
context.read<RoutineBloc>().add(AddToThenContainer({
|
||||
...state.thenItems[index],
|
||||
'imagePath': Assets.delay,
|
||||
'title': 'Delay',
|
||||
}));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
final result = await DeviceDialogHelper.showDeviceDialog(
|
||||
context, state.thenItems[index]);
|
||||
|
||||
if (result != null) {
|
||||
context
|
||||
.read<RoutineBloc>()
|
||||
.add(AddToThenContainer(state.thenItems[index]));
|
||||
} else if (!['AC', '1G', '2G', '3G']
|
||||
.contains(state.thenItems[index]['productType'])) {
|
||||
context
|
||||
.read<RoutineBloc>()
|
||||
.add(AddToThenContainer(state.thenItems[index]));
|
||||
}
|
||||
},
|
||||
child: 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));
|
||||
},
|
||||
),
|
||||
))),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
onWillAccept: (data) => data != null,
|
||||
onAccept: (data) async {
|
||||
// onMove: (details) {
|
||||
// uniqueCustomId = const Uuid().v4();
|
||||
// },
|
||||
// onWillAccept: (data) => data != null,
|
||||
onAcceptWithDetails: (data) async {
|
||||
final uniqueCustomId = const Uuid().v4();
|
||||
|
||||
final mutableData = Map<String, dynamic>.from(data);
|
||||
final mutableData = Map<String, dynamic>.from(data.data);
|
||||
mutableData['uniqueCustomId'] = uniqueCustomId;
|
||||
|
||||
if (mutableData['deviceId'] == 'delay') {
|
||||
final result = await DelayHelper.showDelayPickerDialog(
|
||||
context, mutableData['uniqueCustomId']);
|
||||
final result = await DelayHelper.showDelayPickerDialog(context, mutableData);
|
||||
|
||||
if (result != null) {
|
||||
context.read<RoutineBloc>().add(AddToThenContainer({
|
||||
@ -75,13 +103,11 @@ class ThenContainer extends StatelessWidget {
|
||||
return;
|
||||
}
|
||||
|
||||
final result =
|
||||
await DeviceDialogHelper.showDeviceDialog(context, mutableData);
|
||||
final result = await DeviceDialogHelper.showDeviceDialog(context, mutableData);
|
||||
|
||||
if (result != null) {
|
||||
context.read<RoutineBloc>().add(AddToThenContainer(mutableData));
|
||||
} else if (!['AC', '1G', '2G', '3G']
|
||||
.contains(mutableData['productType'])) {
|
||||
} else if (!['AC', '1G', '2G', '3G'].contains(mutableData['productType'])) {
|
||||
context.read<RoutineBloc>().add(AddToThenContainer(mutableData));
|
||||
}
|
||||
},
|
||||
|
Reference in New Issue
Block a user