From c58f2eb24e9cc6253958b2c5d5b0897f4c8fc69d Mon Sep 17 00:00:00 2001 From: ashraf_personal Date: Tue, 3 Dec 2024 00:29:59 +0300 Subject: [PATCH] fixed autoamtion update --- .../bloc/routine_bloc/routine_bloc.dart | 508 ++++++++++-------- .../bloc/routine_bloc/routine_state.dart | 19 +- .../create_automation_model.dart | 3 +- .../routine_dialogs/automation_dialog.dart | 166 +++--- .../routiens/widgets/then_container.dart | 9 +- 5 files changed, 399 insertions(+), 306 deletions(-) diff --git a/lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart b/lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart index 9cb3adb5..673b439c 100644 --- a/lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart +++ b/lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart @@ -44,7 +44,6 @@ class RoutineBloc extends Bloc { on(_fetchDevices); on(_onUpdateScene); on(_onUpdateAutomation); - on(_onSetAutomationActionExecutor); on(_triggerSwitchTabsEvent); on(_createNewRoutineViewEvent); } @@ -368,21 +367,25 @@ class RoutineBloc extends Bloc { } final actions = state.thenItems.expand((item) { + if (item['type'] == 'tap_to_run') { + return [ + AutomationAction( + actionType: 'scene', + entityId: item['deviceId'], + actionExecutor: 'rule_trigger', + ), + ]; + } + final functions = state.selectedFunctions[item['uniqueCustomId']] ?? []; + return functions.map((function) { if (function.functionCode == 'automation') { return AutomationAction( actionType: 'automation', entityId: function.entityId, actionExecutor: function.value, - ); - } - - if (function.functionCode == 'tap_to_run') { - return AutomationAction( - actionType: 'scene', - entityId: function.entityId, - actionExecutor: function.value, + executorProperty: null, ); } @@ -698,7 +701,7 @@ class RoutineBloc extends Bloc { operationName: 'Automation', ), ); - emit(state.copyWith(automationActionExecutor: action.actionExecutor)); + // emit(state.copyWith(automationActionExecutor: action.actionExecutor)); } else if (action.executorProperty != null && action.actionExecutor != 'delay') { if (!updatedFunctions.containsKey(uniqueCustomId)) { @@ -772,160 +775,6 @@ class RoutineBloc extends Bloc { } } - Future _onGetAutomationDetails( - GetAutomationDetails event, Emitter emit) async { - try { - emit(state.copyWith( - isLoading: true, - isUpdate: true, - isTabToRun: false, - automationId: event.automationId, - isAutomation: true, - ifItems: [], - thenItems: [], - )); - - final automationDetails = - await SceneApi.getAutomationDetails(event.automationId); - - final List> thenItems; - final List> ifItems; - final Map> updatedFunctions = - Map>.from(state.selectedFunctions); - - ifItems = automationDetails.conditions?.map((condition) { - late AllDevicesModel? matchingDevice; - for (var device in state.devices) { - if (device.uuid == condition.entityId) { - matchingDevice = device; - break; - } - } - - final cardData = { - 'entityId': condition.entityId, - 'uniqueCustomId': const Uuid().v4(), - 'deviceId': condition.expr.statusCode == 'delay' - ? 'delay' - : condition.entityId, - 'title': condition.expr.statusCode == 'delay' - ? 'Delay' - : (matchingDevice?.name ?? 'Device'), - 'productType': condition.productType, - 'functions': matchingDevice?.functions ?? [], - 'imagePath': - matchingDevice?.getDefaultIcon(condition.productType) ?? '', - 'device': matchingDevice, - }; - - final functions = matchingDevice?.functions ?? []; - for (var function in functions) { - if (function.code == condition.expr.statusCode) { - updatedFunctions[cardData['uniqueCustomId'].toString()] = [ - DeviceFunctionData( - entityId: condition.entityId, - functionCode: condition.expr.statusCode, - value: condition.expr.statusValue, - operationName: function.operationName, - ), - ]; - break; - } - } - - return cardData; - }).toList() ?? - []; - - // Create then items from actions - thenItems = automationDetails.actions.map((action) { - final matchingDevice = state.devices.firstWhere( - (device) => device.uuid == action.entityId, - orElse: () => AllDevicesModel( - uuid: action.entityId, - name: action.entityId, - productType: action.productType, - ), - ); - - final cardData = { - 'entityId': action.entityId, - 'uniqueCustomId': const Uuid().v4(), - 'deviceId': - action.actionExecutor == 'delay' ? 'delay' : action.entityId, - 'title': action.actionExecutor == 'delay' - ? 'Delay' - : (matchingDevice.name ?? 'Device'), - 'productType': action.productType, - 'functions': matchingDevice.functions, - 'imagePath': matchingDevice.getDefaultIcon(action.productType), - 'device': matchingDevice, - }; - - if (action.executorProperty != null && - action.actionExecutor != 'delay') { - final functions = matchingDevice.functions; - final functionCode = action.executorProperty!.functionCode; - for (var function in functions) { - if (function.code == functionCode) { - updatedFunctions[cardData['uniqueCustomId'].toString()] = [ - DeviceFunctionData( - entityId: action.entityId, - functionCode: functionCode ?? '', - value: action.executorProperty!.functionValue, - operationName: function.operationName, - ), - ]; - break; - } - } - } else if (action.actionExecutor == 'delay') { - final delayFunction = DelayFunction( - deviceId: action.entityId, - deviceName: 'Delay', - ); - updatedFunctions[cardData['uniqueCustomId'].toString()] = [ - DeviceFunctionData( - entityId: action.entityId, - functionCode: 'delay', - value: action.executorProperty?.delaySeconds ?? 0, - operationName: delayFunction.operationName, - ), - ]; - } else if (action.actionExecutor == 'rule_disable' || - action.actionExecutor == 'rule_enable') { - updatedFunctions[cardData['uniqueCustomId'].toString()] = [ - DeviceFunctionData( - entityId: action.entityId, - functionCode: 'automation', - value: action.actionExecutor, - operationName: action.name ?? 'Automation', - ), - ]; - } - - return cardData; - }).toList(); - - emit(state.copyWith( - isLoading: false, - routineName: automationDetails.name, - selectedAutomationOperator: automationDetails.decisionExpr, - effectiveTime: automationDetails.effectiveTime, - isAutomation: true, - thenItems: thenItems, - ifItems: ifItems, - selectedFunctions: updatedFunctions, - automationId: automationDetails.automationId, - )); - } catch (e) { - emit(state.copyWith( - isLoading: false, - errorMessage: 'Failed to load automation details: $e', - )); - } - } - FutureOr _onResetRoutineState( ResetRoutineState event, Emitter emit) { emit(state.copyWith( @@ -1087,65 +936,112 @@ class RoutineBloc extends Bloc { FutureOr _onUpdateAutomation( UpdateAutomation event, Emitter emit) async { - if (_isFirstActionDelay(state.thenItems)) { - emit(state.copyWith( - errorMessage: 'Cannot have delay as the first action', - isLoading: false, - )); - return; - } - emit(state.copyWith(isLoading: true)); try { - final conditions = state.ifItems - .map((item) { - final functions = - state.selectedFunctions[item['uniqueCustomId']] ?? []; - if (functions.isEmpty) return null; + if (state.routineName == null || state.routineName!.isEmpty) { + emit(state.copyWith( + errorMessage: 'Automation name is required', + )); + return; + } + if (_isFirstActionDelay(state.thenItems)) { + emit(state.copyWith( + errorMessage: 'Cannot have delay as the first action', + isLoading: false, + )); + return; + } - final function = functions.first; - return Condition( - code: state.ifItems.indexOf(item) + 1, - entityId: function.entityId, - entityType: item['productType'], - expr: ConditionExpr( - statusCode: function.functionCode, - statusValue: function.value, - comparator: function.condition ?? '==', - ), - ); - }) - .whereType() - .toList(); + if (_isLastActionDelay(state.thenItems)) { + emit(state.copyWith( + errorMessage: 'Cannot have delay as the last action', + isLoading: false, + )); + return; + } + emit(state.copyWith(isLoading: true, errorMessage: null)); - final actions = state.thenItems - .map((item) { - final functions = - state.selectedFunctions[item['uniqueCustomId']] ?? []; - if (functions.isEmpty) return null; + final conditions = state.ifItems.expand((item) { + final functions = state.selectedFunctions[item['uniqueCustomId']] ?? []; + return functions.map((function) { + return Condition( + code: state.selectedFunctions[item['uniqueCustomId']]!.indexOf( + function, + ) + + 1, + entityId: function.entityId, + entityType: 'device_report', + expr: ConditionExpr( + statusCode: function.functionCode, + comparator: function.condition ?? '==', + statusValue: function.value, + ), + ); + }); + }).toList(); - final function = functions.first; + if (conditions.isEmpty) { + emit(state.copyWith( + isLoading: false, + errorMessage: 'At least one condition is required', + )); + return; + } + + final actions = state.thenItems.expand((item) { + if (item['type'] == 'tap_to_run' || item['type'] == 'scene') { + return [ + AutomationAction( + actionType: 'scene', + entityId: item['deviceId'], + actionExecutor: 'rule_trigger', + ), + ]; + } + + final functions = state.selectedFunctions[item['uniqueCustomId']] ?? []; + + return functions.map((function) { + if (function.functionCode == 'automation') { return AutomationAction( actionType: 'automation', entityId: function.entityId, - actionExecutor: function.actionExecutor, + actionExecutor: function.value, + executorProperty: null, + ); + } + + if (item['deviceId'] == 'delay') { + return AutomationAction( + entityId: function.entityId, + actionType: 'automation', + actionExecutor: 'delay', executorProperty: ExecutorProperty( - functionCode: function.functionCode, - functionValue: function.value, - delaySeconds: function.functionCode == 'delay' - ? (function.value as num).toInt() - : null, + delaySeconds: int.tryParse(function.value.toString()) ?? 0, ), ); - }) - .whereType() - .toList(); + } + + return AutomationAction( + entityId: function.entityId, + actionExecutor: 'device_issue', + actionType: 'automation', + executorProperty: ExecutorProperty( + functionCode: function.functionCode, + functionValue: function.value, + ), + ); + }); + }).toList(); final createAutomationModel = CreateAutomationModel( spaceUuid: spaceId, automationName: state.routineName ?? '', decisionExpr: state.selectedAutomationOperator, - effectiveTime: - state.effectiveTime ?? EffectiveTime(start: '', end: '', loops: ''), + effectiveTime: EffectiveTime( + start: state.effectiveTime?.start ?? '00:00', + end: state.effectiveTime?.end ?? '23:59', + loops: state.effectiveTime?.loops ?? '1111111', + ), conditions: conditions, actions: actions, ); @@ -1155,8 +1051,8 @@ class RoutineBloc extends Bloc { if (result['success']) { add(ResetRoutineState()); - add(const LoadScenes(spaceId, communityId)); add(const LoadAutomation(spaceId)); + add(const LoadScenes(spaceId, communityId)); } else { emit(state.copyWith( isLoading: false, @@ -1166,14 +1062,198 @@ class RoutineBloc extends Bloc { } catch (e) { emit(state.copyWith( isLoading: false, - errorMessage: 'Failed to update automation: $e', + errorMessage: 'Something went wrong', )); } } - FutureOr _onSetAutomationActionExecutor( - SetAutomationActionExecutor event, Emitter emit) { - emit(state.copyWith( - automationActionExecutor: event.automationActionExecutor)); + Future _onGetAutomationDetails( + GetAutomationDetails event, Emitter emit) async { + try { + emit(state.copyWith( + isLoading: true, + isUpdate: true, + isTabToRun: false, + automationId: event.automationId, + isAutomation: true, + ifItems: [], + thenItems: [], + )); + + final automationDetails = + await SceneApi.getAutomationDetails(event.automationId); + + final Map> deviceCards = {}; + final Map> updatedFunctions = + Map>.from(state.selectedFunctions); + + for (RoutineCondition condition in automationDetails.conditions ?? []) { + AllDevicesModel? matchingDevice = state.devices.firstWhere( + (device) => device.uuid == condition.entityId, + orElse: () => AllDevicesModel( + uuid: condition.entityId, + name: condition.entityId, + productType: condition.productType, + ), + ); + + final deviceId = condition.entityId; + + if (!deviceCards.containsKey(deviceId)) { + deviceCards[deviceId] = { + 'entityId': condition.entityId, + 'deviceId': condition.entityId, + 'uniqueCustomId': const Uuid().v4(), + 'title': matchingDevice.name ?? 'Device', + 'productType': condition.productType, + 'functions': matchingDevice.functions, + 'imagePath': matchingDevice.getDefaultIcon(condition.productType), + 'device': matchingDevice, + 'type': 'condition', + }; + } + + final cardData = deviceCards[deviceId]!; + final uniqueCustomId = cardData['uniqueCustomId'].toString(); + + if (!updatedFunctions.containsKey(uniqueCustomId)) { + updatedFunctions[uniqueCustomId] = []; + } + + final functions = matchingDevice.functions; + for (var function in functions) { + if (function.code == condition.expr.statusCode) { + updatedFunctions[uniqueCustomId]!.add( + DeviceFunctionData( + entityId: condition.entityId, + functionCode: condition.expr.statusCode, + value: condition.expr.statusValue, + operationName: function.operationName, + ), + ); + break; + } + } + } + + // Process actions (thenItems) + for (var action in automationDetails.actions) { + AllDevicesModel? matchingDevice = state.devices.firstWhere( + (device) => device.uuid == action.entityId, + orElse: () => AllDevicesModel( + uuid: action.entityId, + name: action.entityId, + productType: action.productType, + ), + ); + + final deviceId = action.actionExecutor == 'delay' + ? '${action.entityId}_delay' + : action.entityId; + + if (!deviceCards.containsKey(deviceId)) { + deviceCards[deviceId] = { + 'entityId': action.entityId, + 'deviceId': + action.actionExecutor == 'delay' ? 'delay' : action.entityId, + 'uniqueCustomId': const Uuid().v4(), + 'title': action.actionExecutor == 'delay' + ? 'Delay' + : (action.type == 'scene' || action.type == 'automation') + ? action.name + : (matchingDevice.name ?? 'Device'), + 'productType': action.productType, + 'functions': matchingDevice.functions, + 'imagePath': action.actionExecutor == 'delay' + ? Assets.delay + : action.type == 'automation' + ? Assets.automation + : matchingDevice.getDefaultIcon(action.productType), + 'device': matchingDevice, + 'type': action.type == 'scene' + ? 'scene' + : action.type == 'automation' + ? 'automation' + : 'action', + }; + } + + final cardData = deviceCards[deviceId]!; + final uniqueCustomId = cardData['uniqueCustomId'].toString(); + + if (!updatedFunctions.containsKey(uniqueCustomId)) { + updatedFunctions[uniqueCustomId] = []; + } + + if (action.executorProperty != null && + action.actionExecutor != 'delay') { + final functions = matchingDevice.functions; + final functionCode = action.executorProperty!.functionCode; + for (var function in functions) { + if (function.code == functionCode) { + updatedFunctions[uniqueCustomId]!.add( + DeviceFunctionData( + entityId: action.entityId, + functionCode: functionCode ?? '', + value: action.executorProperty!.functionValue, + operationName: function.operationName, + ), + ); + break; + } + } + } else if (action.actionExecutor == 'delay') { + final delayFunction = DelayFunction( + deviceId: action.entityId, + deviceName: 'Delay', + ); + updatedFunctions[uniqueCustomId]!.add( + DeviceFunctionData( + entityId: action.entityId, + functionCode: 'delay', + value: action.executorProperty?.delaySeconds ?? 0, + operationName: delayFunction.operationName, + ), + ); + } else if (action.actionExecutor == 'rule_disable' || + action.actionExecutor == 'rule_enable') { + updatedFunctions[uniqueCustomId]!.add( + DeviceFunctionData( + entityId: action.entityId, + functionCode: 'automation', + value: action.actionExecutor, + operationName: action.name ?? 'Automation', + ), + ); + } + } + + final ifItems = deviceCards.values + .where((card) => card['type'] == 'condition') + .toList(); + final thenItems = deviceCards.values + .where((card) => + card['type'] == 'action' || + card['type'] == 'automation' || + card['type'] == 'scene') + .toList(); + + emit(state.copyWith( + isLoading: false, + routineName: automationDetails.name, + selectedAutomationOperator: automationDetails.decisionExpr, + effectiveTime: automationDetails.effectiveTime, + isAutomation: true, + thenItems: thenItems, + ifItems: ifItems, + selectedFunctions: updatedFunctions, + automationId: automationDetails.automationId, + )); + } catch (e) { + emit(state.copyWith( + isLoading: false, + errorMessage: 'Failed to load automation details: $e', + )); + } } } diff --git a/lib/pages/routiens/bloc/routine_bloc/routine_state.dart b/lib/pages/routiens/bloc/routine_bloc/routine_state.dart index e7dce718..4dc26a01 100644 --- a/lib/pages/routiens/bloc/routine_bloc/routine_state.dart +++ b/lib/pages/routiens/bloc/routine_bloc/routine_state.dart @@ -22,7 +22,7 @@ class RoutineState extends Equatable { final String? automationId; final bool? isUpdate; final List devices; - final String? automationActionExecutor; + // final String? automationActionExecutor; final bool routineTab; final bool createRoutineView; @@ -48,7 +48,7 @@ class RoutineState extends Equatable { this.automationId, this.isUpdate, this.devices = const [], - this.automationActionExecutor, + // this.automationActionExecutor, this.routineTab = false, this.createRoutineView = false}); @@ -73,7 +73,7 @@ class RoutineState extends Equatable { String? automationId, bool? isUpdate, List? devices, - String? automationActionExecutor, + // String? automationActionExecutor, TextEditingController? nameController, bool? routineTab, bool? createRoutineView, @@ -88,18 +88,21 @@ class RoutineState extends Equatable { errorMessage: errorMessage ?? this.errorMessage, routineName: routineName ?? this.routineName, selectedIcon: selectedIcon ?? this.selectedIcon, - loadScenesErrorMessage: loadScenesErrorMessage ?? this.loadScenesErrorMessage, - loadAutomationErrorMessage: loadAutomationErrorMessage ?? this.loadAutomationErrorMessage, + loadScenesErrorMessage: + loadScenesErrorMessage ?? this.loadScenesErrorMessage, + loadAutomationErrorMessage: + loadAutomationErrorMessage ?? this.loadAutomationErrorMessage, searchText: searchText ?? this.searchText, isTabToRun: isTabToRun ?? this.isTabToRun, isAutomation: isAutomation ?? this.isAutomation, - selectedAutomationOperator: selectedAutomationOperator ?? this.selectedAutomationOperator, + selectedAutomationOperator: + selectedAutomationOperator ?? this.selectedAutomationOperator, effectiveTime: effectiveTime ?? this.effectiveTime, sceneId: sceneId ?? this.sceneId, automationId: automationId ?? this.automationId, isUpdate: isUpdate ?? this.isUpdate, devices: devices ?? this.devices, - automationActionExecutor: automationActionExecutor ?? this.automationActionExecutor, + // automationActionExecutor: automationActionExecutor ?? this.automationActionExecutor, routineTab: routineTab ?? this.routineTab, createRoutineView: createRoutineView ?? this.createRoutineView); } @@ -126,7 +129,7 @@ class RoutineState extends Equatable { automationId, isUpdate, devices, - automationActionExecutor, + // automationActionExecutor, routineTab, createRoutineView ]; diff --git a/lib/pages/routiens/models/create_scene_and_autoamtion/create_automation_model.dart b/lib/pages/routiens/models/create_scene_and_autoamtion/create_automation_model.dart index d76c34de..467c492c 100644 --- a/lib/pages/routiens/models/create_scene_and_autoamtion/create_automation_model.dart +++ b/lib/pages/routiens/models/create_scene_and_autoamtion/create_automation_model.dart @@ -152,7 +152,8 @@ class AutomationAction { return { 'entityId': entityId, 'actionExecutor': actionExecutor, - 'executorProperty': executorProperty?.toMap(), + if (executorProperty != null) + 'executorProperty': executorProperty?.toMap(), 'actionType': actionType }; } diff --git a/lib/pages/routiens/widgets/routine_dialogs/automation_dialog.dart b/lib/pages/routiens/widgets/routine_dialogs/automation_dialog.dart index 2950c0cc..84ed8fdd 100644 --- a/lib/pages/routiens/widgets/routine_dialogs/automation_dialog.dart +++ b/lib/pages/routiens/widgets/routine_dialogs/automation_dialog.dart @@ -7,100 +7,106 @@ import 'package:syncrow_web/pages/routiens/widgets/dialog_header.dart'; import 'package:syncrow_web/pages/routiens/widgets/dialog_footer.dart'; import 'package:syncrow_web/utils/constants/assets.dart'; -class AutomationDialog extends StatelessWidget { +class AutomationDialog extends StatefulWidget { final String automationName; final String automationId; final String uniqueCustomId; + final String? passedAutomationActionExecutor; const AutomationDialog({ super.key, required this.automationName, required this.automationId, required this.uniqueCustomId, + this.passedAutomationActionExecutor, }); @override - Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - final String? initialSelection = state.automationActionExecutor; + State createState() => _AutomationDialogState(); +} - return Dialog( - shape: - RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)), - child: Container( - width: 400, - padding: const EdgeInsets.all(16), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - DialogHeader(automationName), - const SizedBox(height: 16), - ListTile( - leading: - SvgPicture.asset(Assets.acPower, width: 24, height: 24), - title: const Text('Enable'), - trailing: Radio( - value: 'rule_enable', - groupValue: initialSelection, - onChanged: (String? value) { - if (value != null) { - context.read().add( - SetAutomationActionExecutor( - automationActionExecutor: value, - ), - ); - } - }, - ), - ), - ListTile( - leading: SvgPicture.asset(Assets.acPowerOff, - width: 24, height: 24), - title: const Text('Disable'), - trailing: Radio( - value: 'rule_disable', - groupValue: initialSelection, - onChanged: (String? value) { - if (value != null) { - context.read().add( - SetAutomationActionExecutor( - automationActionExecutor: value, - ), - ); - } - }, - ), - ), - const SizedBox(height: 16), - DialogFooter( - onConfirm: () { - if (state.automationActionExecutor != null) { - context.read().add( - AddFunctionToRoutine( - [ - DeviceFunctionData( - entityId: automationId, - functionCode: 'automation', - value: state.automationActionExecutor, - operationName: 'Automation', - ), - ], - uniqueCustomId, - ), - ); - Navigator.of(context).pop(true); - } - }, - onCancel: () => Navigator.of(context).pop(false), - isConfirmEnabled: state.automationActionExecutor != null, - dialogWidth: 400, - ), - ], +class _AutomationDialogState extends State { + String? selectedAutomationActionExecutor; + + @override + void initState() { + super.initState(); + List? functions = context + .read() + .state + .selectedFunctions[widget.uniqueCustomId]; + for (DeviceFunctionData data in functions ?? []) { + if (data.entityId == widget.automationId) { + selectedAutomationActionExecutor = data.value; + } + } + } + + @override + Widget build(BuildContext context) { + return Dialog( + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)), + child: Container( + width: 400, + padding: const EdgeInsets.all(16), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + DialogHeader(widget.automationName), + const SizedBox(height: 16), + ListTile( + leading: SvgPicture.asset(Assets.acPower, width: 24, height: 24), + title: const Text('Enable'), + trailing: Radio( + value: 'rule_enable', + groupValue: selectedAutomationActionExecutor, + onChanged: (String? value) { + setState(() { + selectedAutomationActionExecutor = 'rule_enable'; + }); + }), ), - ), - ); - }, + ListTile( + leading: + SvgPicture.asset(Assets.acPowerOff, width: 24, height: 24), + title: const Text('Disable'), + trailing: Radio( + value: 'rule_disable', + groupValue: selectedAutomationActionExecutor, + onChanged: (String? value) { + setState(() { + selectedAutomationActionExecutor = 'rule_disable'; + }); + }, + ), + ), + const SizedBox(height: 16), + DialogFooter( + onConfirm: () { + if (selectedAutomationActionExecutor != null) { + context.read().add( + AddFunctionToRoutine( + [ + DeviceFunctionData( + entityId: widget.automationId, + functionCode: 'automation', + value: selectedAutomationActionExecutor, + operationName: 'Automation', + ), + ], + widget.uniqueCustomId, + ), + ); + } + Navigator.of(context).pop(true); + }, + onCancel: () => Navigator.of(context).pop(), + isConfirmEnabled: selectedAutomationActionExecutor != null, + dialogWidth: 400, + ), + ], + ), + ), ); } } diff --git a/lib/pages/routiens/widgets/then_container.dart b/lib/pages/routiens/widgets/then_container.dart index d959c372..69a1c278 100644 --- a/lib/pages/routiens/widgets/then_container.dart +++ b/lib/pages/routiens/widgets/then_container.dart @@ -87,8 +87,11 @@ class ThenContainer extends StatelessWidget { ...state.thenItems[index], 'imagePath': Assets.automation, - 'title': state - .thenItems[index]['name'], + 'title': + state.thenItems[index] + ['name'] ?? + state.thenItems[index] + ['title'], })); } return; @@ -171,7 +174,7 @@ class ThenContainer extends StatelessWidget { if (mutableData['type'] == 'tap_to_run' && state.isAutomation) { context.read().add(AddToThenContainer({ ...mutableData, - 'imagePath': Assets.logo, + 'imagePath': mutableData['imagePath'] ?? Assets.logo, 'title': mutableData['name'], }));