From 03f7b962238757d2fa611139b4e3927dd4c13ecc Mon Sep 17 00:00:00 2001 From: Abdullah Alassaf Date: Wed, 27 Nov 2024 00:53:48 +0300 Subject: [PATCH] bug fixes in setting and if contianer --- .../effective_period/effect_period_bloc.dart | 20 - .../bloc/routine_bloc/routine_bloc.dart | 110 ++- .../bloc/routine_bloc/routine_event.dart | 6 +- .../routiens/view/effective_period_view.dart | 63 +- lib/pages/routiens/widgets/if_container.dart | 79 +- lib/pages/routiens/widgets/period_option.dart | 16 +- .../routine_dialogs/setting_dialog.dart | 815 ++++++++---------- .../widgets/routine_search_and_buttons.dart | 362 ++++---- .../routiens/widgets/then_container.dart | 62 +- 9 files changed, 731 insertions(+), 802 deletions(-) diff --git a/lib/pages/routiens/bloc/effective_period/effect_period_bloc.dart b/lib/pages/routiens/bloc/effective_period/effect_period_bloc.dart index b5a293a1..f4db836b 100644 --- a/lib/pages/routiens/bloc/effective_period/effect_period_bloc.dart +++ b/lib/pages/routiens/bloc/effective_period/effect_period_bloc.dart @@ -2,10 +2,7 @@ import 'dart:async'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_event.dart'; import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_state.dart'; -import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; -import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_automation_model.dart'; import 'package:syncrow_web/utils/constants/app_enum.dart'; -import 'package:syncrow_web/utils/navigation_service.dart'; class EffectPeriodBloc extends Bloc { final daysMap = { @@ -52,10 +49,6 @@ class EffectPeriodBloc extends Bloc { break; } - BlocProvider.of(NavigationService.navigatorKey.currentContext!).add( - EffectiveTimePeriodEvent( - EffectiveTime(start: startTime, end: endTime, loops: state.selectedDaysBinary))); - emit(state.copyWith( selectedPeriod: event.period, customStartTime: startTime, customEndTime: endTime)); } @@ -70,12 +63,6 @@ class EffectPeriodBloc extends Bloc { } final newDaysBinary = daysList.join(); emit(state.copyWith(selectedDaysBinary: newDaysBinary)); - - BlocProvider.of(NavigationService.navigatorKey.currentContext!).add( - EffectiveTimePeriodEvent(EffectiveTime( - start: state.customStartTime ?? '00:00', - end: state.customEndTime ?? '23:59', - loops: newDaysBinary))); } void _onSetCustomTime(SetCustomTime event, Emitter emit) { @@ -96,10 +83,6 @@ class EffectPeriodBloc extends Bloc { emit( state.copyWith(customStartTime: startTime, customEndTime: endTime, selectedPeriod: period)); - - BlocProvider.of(NavigationService.navigatorKey.currentContext!).add( - EffectiveTimePeriodEvent( - EffectiveTime(start: startTime, end: endTime, loops: state.selectedDaysBinary))); } void _onResetEffectivePeriod(ResetEffectivePeriod event, Emitter emit) { @@ -108,9 +91,6 @@ class EffectPeriodBloc extends Bloc { customStartTime: '00:00', customEndTime: '23:59', selectedDaysBinary: '1111111')); - - BlocProvider.of(NavigationService.navigatorKey.currentContext!).add( - EffectiveTimePeriodEvent(EffectiveTime(start: '00:00', end: '23:59', loops: '1111111'))); } void _onResetDays(ResetDays event, Emitter emit) { diff --git a/lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart b/lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart index 7694e8ec..45447ed4 100644 --- a/lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart +++ b/lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart @@ -37,24 +37,31 @@ class RoutineBloc extends Bloc { } void _onAddToIfContainer(AddToIfContainer event, Emitter emit) { - final updatedIfItems = List>.from(state.ifItems) - ..add(event.item); - if (event.isTabToRun) { - emit(state.copyWith( - ifItems: updatedIfItems, isTabToRun: true, isAutomation: false)); + final updatedIfItems = List>.from(state.ifItems); + + // Find the index of the item in teh current itemsList + int index = + updatedIfItems.indexWhere((map) => map['uniqueCustomId'] == event.item['uniqueCustomId']); + // Replace the map if the index is valid + if (index != -1) { + updatedIfItems[index] = event.item; } else { - emit(state.copyWith( - ifItems: updatedIfItems, isTabToRun: false, isAutomation: true)); + updatedIfItems.add(event.item); + } + + if (event.isTabToRun) { + emit(state.copyWith(ifItems: updatedIfItems, isTabToRun: true, isAutomation: false)); + } else { + emit(state.copyWith(ifItems: updatedIfItems, isTabToRun: false, isAutomation: true)); } } - void _onAddToThenContainer( - AddToThenContainer event, Emitter emit) { + void _onAddToThenContainer(AddToThenContainer event, Emitter emit) { final currentItems = List>.from(state.thenItems); // Find the index of the item in teh current itemsList - int index = currentItems.indexWhere( - (map) => map['uniqueCustomId'] == event.item['uniqueCustomId']); + 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; @@ -65,21 +72,38 @@ class RoutineBloc extends Bloc { emit(state.copyWith(thenItems: currentItems)); } - void _onAddFunctionsToRoutine( - AddFunctionToRoutine event, Emitter emit) { + void _onAddFunctionsToRoutine(AddFunctionToRoutine event, Emitter emit) { try { if (event.functions.isEmpty) return; - final currentSelectedFunctions = - Map>.from(state.selectedFunctions); + List selectedFunction = List.from(event.functions); + Map> currentSelectedFunctions = + Map>.from(state.selectedFunctions); if (currentSelectedFunctions.containsKey(event.uniqueCustomId)) { - currentSelectedFunctions[event.uniqueCustomId] = - List.from(currentSelectedFunctions[event.uniqueCustomId]!) - ..addAll(event.functions); + List currentFunctions = + List.from(currentSelectedFunctions[event.uniqueCustomId] ?? []); + + List functionCode = []; + for (int i = 0; i < selectedFunction.length; i++) { + for (int j = 0; j < currentFunctions.length; j++) { + if (selectedFunction[i].functionCode == currentFunctions[j].functionCode) { + currentFunctions[j] = selectedFunction[i]; + if (!functionCode.contains(currentFunctions[j].functionCode)) { + functionCode.add(currentFunctions[j].functionCode); + } + } + } + } + + for (int i = 0; i < functionCode.length; i++) { + selectedFunction.removeWhere((code) => code.functionCode == functionCode[i]); + } + + currentSelectedFunctions[event.uniqueCustomId] = List.from(currentFunctions) + ..addAll(selectedFunction); } else { - currentSelectedFunctions[event.uniqueCustomId] = - List.from(event.functions); + currentSelectedFunctions[event.uniqueCustomId] = List.from(event.functions); } emit(state.copyWith(selectedFunctions: currentSelectedFunctions)); @@ -88,8 +112,7 @@ class RoutineBloc extends Bloc { } } - Future _onLoadScenes( - LoadScenes event, Emitter emit) async { + Future _onLoadScenes(LoadScenes event, Emitter emit) async { emit(state.copyWith(isLoading: true, errorMessage: null)); try { @@ -108,8 +131,7 @@ class RoutineBloc extends Bloc { } } - Future _onLoadAutomation( - LoadAutomation event, Emitter emit) async { + Future _onLoadAutomation(LoadAutomation event, Emitter emit) async { emit(state.copyWith(isLoading: true, errorMessage: null)); try { @@ -128,15 +150,13 @@ class RoutineBloc extends Bloc { } } - FutureOr _onSearchRoutines( - SearchRoutines event, Emitter emit) async { + FutureOr _onSearchRoutines(SearchRoutines event, Emitter emit) async { emit(state.copyWith(isLoading: true, errorMessage: null)); await Future.delayed(const Duration(seconds: 1)); emit(state.copyWith(searchText: event.query)); } - FutureOr _onAddSelectedIcon( - AddSelectedIcon event, Emitter emit) { + FutureOr _onAddSelectedIcon(AddSelectedIcon event, Emitter emit) { emit(state.copyWith(selectedIcon: event.icon)); } @@ -145,8 +165,7 @@ class RoutineBloc extends Bloc { return actions.first['deviceId'] == 'delay'; } - Future _onCreateScene( - CreateSceneEvent event, Emitter emit) async { + Future _onCreateScene(CreateSceneEvent event, Emitter emit) async { try { // Check if first action is delay if (_isFirstActionDelay(state.thenItems)) { @@ -161,8 +180,7 @@ class RoutineBloc extends Bloc { final actions = state.thenItems .map((item) { - final functions = - state.selectedFunctions[item['uniqueCustomId']] ?? []; + final functions = state.selectedFunctions[item['uniqueCustomId']] ?? []; if (functions.isEmpty) return null; final function = functions.first; @@ -217,8 +235,7 @@ class RoutineBloc extends Bloc { } } - Future _onCreateAutomation( - CreateAutomationEvent event, Emitter emit) async { + Future _onCreateAutomation(CreateAutomationEvent event, Emitter emit) async { try { if (state.routineName == null || state.routineName!.isEmpty) { emit(state.copyWith( @@ -231,8 +248,7 @@ class RoutineBloc extends Bloc { final conditions = state.ifItems .map((item) { - final functions = - state.selectedFunctions[item['uniqueCustomId']] ?? []; + final functions = state.selectedFunctions[item['uniqueCustomId']] ?? []; if (functions.isEmpty) return null; final function = functions.first; @@ -271,8 +287,7 @@ class RoutineBloc extends Bloc { conditions: conditions, actions: state.thenItems .map((item) { - final functions = - state.selectedFunctions[item['uniqueCustomId']] ?? []; + final functions = state.selectedFunctions[item['uniqueCustomId']] ?? []; if (functions.isEmpty) return null; final function = functions.first; @@ -327,16 +342,21 @@ class RoutineBloc extends Bloc { } } - FutureOr _onRemoveDragCard( - RemoveDragCard event, Emitter emit) { + FutureOr _onRemoveDragCard(RemoveDragCard event, Emitter emit) { if (event.isFromThen) { final thenItems = List>.from(state.thenItems); + final selectedFunctions = Map>.from(state.selectedFunctions); + thenItems.removeAt(event.index); - emit(state.copyWith(thenItems: thenItems)); + selectedFunctions.remove(event.key); + emit(state.copyWith(thenItems: thenItems, selectedFunctions: selectedFunctions)); } else { final ifItems = List>.from(state.ifItems); + final selectedFunctions = Map>.from(state.selectedFunctions); + ifItems.removeAt(event.index); - emit(state.copyWith(ifItems: ifItems)); + selectedFunctions.remove(event.key); + emit(state.copyWith(ifItems: ifItems, selectedFunctions: selectedFunctions)); } } @@ -347,13 +367,11 @@ class RoutineBloc extends Bloc { )); } - FutureOr _onEffectiveTimeEvent( - EffectiveTimePeriodEvent event, Emitter emit) { + FutureOr _onEffectiveTimeEvent(EffectiveTimePeriodEvent event, Emitter emit) { emit(state.copyWith(effectiveTime: event.effectiveTime)); } - FutureOr _onSetRoutineName( - SetRoutineName event, Emitter emit) { + FutureOr _onSetRoutineName(SetRoutineName event, Emitter emit) { emit(state.copyWith(routineName: event.name)); } } diff --git a/lib/pages/routiens/bloc/routine_bloc/routine_event.dart b/lib/pages/routiens/bloc/routine_bloc/routine_event.dart index 9337e88e..6f1b8a95 100644 --- a/lib/pages/routiens/bloc/routine_bloc/routine_event.dart +++ b/lib/pages/routiens/bloc/routine_bloc/routine_event.dart @@ -82,9 +82,10 @@ class CreateSceneEvent extends RoutineEvent { class RemoveDragCard extends RoutineEvent { final int index; final bool isFromThen; - const RemoveDragCard({required this.index, required this.isFromThen}); + final String key; + const RemoveDragCard({required this.index, required this.isFromThen, required this.key}); @override - List get props => [index]; + List get props => [index, isFromThen, key]; } class ChangeAutomationOperator extends RoutineEvent { @@ -121,4 +122,5 @@ class SetRoutineName extends RoutineEvent { @override List get props => [name]; } + class ClearFunctions extends RoutineEvent {} diff --git a/lib/pages/routiens/view/effective_period_view.dart b/lib/pages/routiens/view/effective_period_view.dart index d9d9bc2f..5e6c33da 100644 --- a/lib/pages/routiens/view/effective_period_view.dart +++ b/lib/pages/routiens/view/effective_period_view.dart @@ -1,6 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_bloc.dart'; import 'package:syncrow_web/pages/routiens/widgets/routine_dialogs/effictive_period_dialog.dart'; import 'package:syncrow_web/pages/routiens/widgets/period_option.dart'; import 'package:syncrow_web/pages/routiens/widgets/repeat_days.dart'; @@ -11,39 +9,36 @@ class EffectivePeriodView extends StatelessWidget { @override Widget build(BuildContext context) { - return BlocProvider( - create: (_) => EffectPeriodBloc(), - child: Padding( - padding: const EdgeInsets.all(16.0), - child: ListView( - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - const Spacer(), - Expanded( - child: Text( - 'Effective Period', - style: Theme.of(context).textTheme.bodyMedium!.copyWith( - color: ColorsManager.textPrimaryColor, - fontWeight: FontWeight.w400, - fontSize: 14), - ), + return Padding( + padding: const EdgeInsets.all(16.0), + child: ListView( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + const Spacer(), + Expanded( + child: Text( + 'Effective Period', + style: Theme.of(context).textTheme.bodyMedium!.copyWith( + color: ColorsManager.textPrimaryColor, + fontWeight: FontWeight.w400, + fontSize: 14), ), - const Spacer(), - ], - ), - const Divider( - color: ColorsManager.backgroundColor, - ), - const PeriodOptions( - showCustomTimePicker: EffectPeriodHelper.showCustomTimePicker, - ), - const SizedBox(height: 16), - const RepeatDays(), - const SizedBox(height: 24), - ], - ), + ), + const Spacer(), + ], + ), + const Divider( + color: ColorsManager.backgroundColor, + ), + const PeriodOptions( + showCustomTimePicker: EffectPeriodHelper.showCustomTimePicker, + ), + const SizedBox(height: 16), + const RepeatDays(), + const SizedBox(height: 24), + ], ), ); } diff --git a/lib/pages/routiens/widgets/if_container.dart b/lib/pages/routiens/widgets/if_container.dart index 57577f64..d0273adc 100644 --- a/lib/pages/routiens/widgets/if_container.dart +++ b/lib/pages/routiens/widgets/if_container.dart @@ -26,9 +26,7 @@ class IfContainer extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - const Text('IF', - style: TextStyle( - fontSize: 18, fontWeight: FontWeight.bold)), + const Text('IF', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), if (state.isAutomation) AutomationOperatorSelector( selectedOperator: state.selectedAutomationOperator), @@ -52,20 +50,38 @@ class IfContainer extends StatelessWidget { 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().add( - RemoveDragCard( - index: index, isFromThen: false)); + (index) => GestureDetector( + onTap: () async { + if (!state.isTabToRun) { + final result = await DeviceDialogHelper.showDeviceDialog( + context, state.ifItems[index]); + + if (result != null) { + context + .read() + .add(AddToIfContainer(state.ifItems[index], false)); + } else if (!['AC', '1G', '2G', '3G'] + .contains(state.ifItems[index]['productType'])) { + context + .read() + .add(AddToIfContainer(state.ifItems[index], false)); + } + } }, + child: 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().add(RemoveDragCard( + index: index, + isFromThen: false, + key: state.ifItems[index]['uniqueCustomId'])); + }, + ), )), ), ], @@ -81,22 +97,14 @@ class IfContainer extends StatelessWidget { if (!state.isTabToRun) { if (mutableData['deviceId'] == 'tab_to_run') { - context - .read() - .add(AddToIfContainer(mutableData, true)); + context.read().add(AddToIfContainer(mutableData, true)); } else { - final result = await DeviceDialogHelper.showDeviceDialog( - context, mutableData); + final result = await DeviceDialogHelper.showDeviceDialog(context, mutableData); if (result != null) { - context - .read() - .add(AddToIfContainer(mutableData, false)); - } else if (!['AC', '1G', '2G', '3G'] - .contains(mutableData['productType'])) { - context - .read() - .add(AddToIfContainer(mutableData, false)); + context.read().add(AddToIfContainer(mutableData, false)); + } else if (!['AC', '1G', '2G', '3G'].contains(mutableData['productType'])) { + context.read().add(AddToIfContainer(mutableData, false)); } } } @@ -136,15 +144,12 @@ class AutomationOperatorSelector extends StatelessWidget { child: Text( 'Any condition is met', style: context.textTheme.bodyMedium?.copyWith( - color: selectedOperator == 'or' - ? ColorsManager.whiteColors - : ColorsManager.blackColor, + color: + selectedOperator == 'or' ? ColorsManager.whiteColors : ColorsManager.blackColor, ), ), onPressed: () { - context - .read() - .add(const ChangeAutomationOperator(operator: 'or')); + context.read().add(const ChangeAutomationOperator(operator: 'or')); }, ), Container( @@ -170,9 +175,7 @@ class AutomationOperatorSelector extends StatelessWidget { ), ), onPressed: () { - context - .read() - .add(const ChangeAutomationOperator(operator: 'and')); + context.read().add(const ChangeAutomationOperator(operator: 'and')); }, ), ], diff --git a/lib/pages/routiens/widgets/period_option.dart b/lib/pages/routiens/widgets/period_option.dart index 8a89e2f9..5c1c2d51 100644 --- a/lib/pages/routiens/widgets/period_option.dart +++ b/lib/pages/routiens/widgets/period_option.dart @@ -21,12 +21,9 @@ class PeriodOptions extends StatelessWidget { builder: (context, state) { return Column( children: [ - _buildRadioOption( - context, EnumEffectivePeriodOptions.allDay, '24 Hours'), - _buildRadioOption(context, EnumEffectivePeriodOptions.daytime, - 'Sunrise to Sunset'), - _buildRadioOption( - context, EnumEffectivePeriodOptions.night, 'Sunset to Sunrise'), + _buildRadioOption(context, EnumEffectivePeriodOptions.allDay, '24 Hours'), + _buildRadioOption(context, EnumEffectivePeriodOptions.daytime, 'Sunrise to Sunset'), + _buildRadioOption(context, EnumEffectivePeriodOptions.night, 'Sunset to Sunrise'), ListTile( contentPadding: EdgeInsets.zero, onTap: () => showCustomTimePicker(context), @@ -37,8 +34,7 @@ class PeriodOptions extends StatelessWidget { fontWeight: FontWeight.w400, fontSize: 14), ), - subtitle: state.customStartTime != null && - state.customEndTime != null + subtitle: state.customStartTime != null && state.customEndTime != null ? Text( '${"${state.customStartTime}"} - ${"${state.customEndTime}"}', style: Theme.of(context).textTheme.bodyMedium!.copyWith( @@ -83,9 +79,7 @@ class PeriodOptions extends StatelessWidget { subtitle: Text( subtitle, style: Theme.of(context).textTheme.bodyMedium!.copyWith( - color: ColorsManager.textPrimaryColor, - fontWeight: FontWeight.w400, - fontSize: 10), + color: ColorsManager.textPrimaryColor, fontWeight: FontWeight.w400, fontSize: 10), ), trailing: Radio( value: value, diff --git a/lib/pages/routiens/widgets/routine_dialogs/setting_dialog.dart b/lib/pages/routiens/widgets/routine_dialogs/setting_dialog.dart index 4e2bdde6..7fc723af 100644 --- a/lib/pages/routiens/widgets/routine_dialogs/setting_dialog.dart +++ b/lib/pages/routiens/widgets/routine_dialogs/setting_dialog.dart @@ -1,9 +1,12 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_bloc.dart'; +import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_state.dart'; import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; import 'package:syncrow_web/pages/routiens/bloc/setting_bloc/setting_bloc.dart'; import 'package:syncrow_web/pages/routiens/bloc/setting_bloc/setting_event.dart'; import 'package:syncrow_web/pages/routiens/bloc/setting_bloc/setting_state.dart'; +import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_automation_model.dart'; import 'package:syncrow_web/pages/routiens/models/icon_model.dart'; import 'package:syncrow_web/pages/routiens/view/effective_period_view.dart'; import 'package:syncrow_web/pages/routiens/widgets/dialog_header.dart'; @@ -19,444 +22,392 @@ class SettingHelper { context: context, builder: (BuildContext context) { final isAutomation = context.read().state.isAutomation; - return BlocProvider( - create: (_) => - SettingBloc()..add(InitialEvent(selectedIcon: iconId ?? '')), + return MultiBlocProvider( + providers: [ + BlocProvider( + create: (_) => EffectPeriodBloc(), + ), + BlocProvider( + create: (_) => SettingBloc()..add(InitialEvent(selectedIcon: iconId ?? ''))), + ], child: AlertDialog( contentPadding: EdgeInsets.zero, - content: BlocBuilder( - builder: (context, state) { - String selectedIcon = ''; - List list = []; - if (state is TabToRunSettingLoaded) { - selectedIcon = state.selectedIcon; - list = state.iconList; - } - return Container( - width: context.read().isExpanded ? 800 : 400, - height: context.read().isExpanded && isAutomation - ? 500 - : 300, - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(20), - ), - padding: const EdgeInsets.only(top: 20), - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const DialogHeader('Settings'), - Row( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox( - width: 400, - child: isAutomation - ? Column( - mainAxisSize: MainAxisSize.min, - children: [ - Container( - padding: const EdgeInsets.only( - top: 10, - left: 10, - right: 10, - bottom: 10), - child: Column( - children: [ - InkWell( - onTap: () {}, - child: Row( - mainAxisAlignment: - MainAxisAlignment - .spaceBetween, - children: [ - Text( - 'Validity', - style: Theme.of(context) - .textTheme - .bodyMedium! - .copyWith( - color: ColorsManager - .textPrimaryColor, - fontWeight: - FontWeight - .w400, - fontSize: 14), - ), - const Icon( - Icons - .arrow_forward_ios_outlined, - color: ColorsManager - .textGray, - size: 15, - ) - ], - ), - ), - const SizedBox( - height: 5, - ), - const Divider( - color: ColorsManager.graysColor, - ), - const SizedBox( - height: 5, - ), - InkWell( - onTap: () { - BlocProvider.of( - context) - .add(FetchIcons( - expanded: !context - .read< - SettingBloc>() - .isExpanded)); - }, - child: Row( - mainAxisAlignment: - MainAxisAlignment - .spaceBetween, - children: [ - Text( - 'Effective Period', - style: Theme.of(context) - .textTheme - .bodyMedium! - .copyWith( - color: ColorsManager - .textPrimaryColor, - fontWeight: - FontWeight - .w400, - fontSize: 14), - ), - const Icon( - Icons - .arrow_forward_ios_outlined, - color: ColorsManager - .textGray, - size: 15, - ) - ], - ), - ), - const SizedBox( - height: 5, - ), - const Divider( - color: ColorsManager.graysColor, - ), - const SizedBox( - height: 5, - ), - Row( - mainAxisAlignment: - MainAxisAlignment - .spaceBetween, - children: [ - Text( - 'Executed by', - style: Theme.of(context) - .textTheme - .bodyMedium! - .copyWith( - color: ColorsManager - .textPrimaryColor, - fontWeight: - FontWeight.w400, - fontSize: 14), - ), - Text('Cloud', - style: Theme.of(context) - .textTheme - .bodyMedium! - .copyWith( - color: - ColorsManager - .textGray, - fontWeight: - FontWeight - .w400, - fontSize: 14)), - ], - ), - ], - )), - ], - ) - : Column( - mainAxisSize: MainAxisSize.min, - children: [ - Container( - padding: const EdgeInsets.only( - top: 10, - left: 10, - right: 10, - bottom: 10), - child: Column( - children: [ - InkWell( - onTap: () { - BlocProvider.of( - context) - .add(FetchIcons( - expanded: !context - .read< - SettingBloc>() - .isExpanded)); - }, - child: Row( - mainAxisAlignment: - MainAxisAlignment - .spaceBetween, - children: [ - Text( - 'Icons', - style: Theme.of(context) - .textTheme - .bodyMedium! - .copyWith( - color: ColorsManager - .textPrimaryColor, - fontWeight: - FontWeight - .w400, - fontSize: 14), - ), - const Icon( - Icons - .arrow_forward_ios_outlined, - color: ColorsManager - .textGray, - size: 15, - ) - ], - ), - ), - const SizedBox( - height: 5, - ), - const Divider( - color: ColorsManager.graysColor, - ), - const SizedBox( - height: 5, - ), - Row( - mainAxisAlignment: - MainAxisAlignment - .spaceBetween, - children: [ - Text( - 'Show on devices page', - style: Theme.of(context) - .textTheme - .bodyMedium! - .copyWith( - color: ColorsManager - .textPrimaryColor, - fontWeight: - FontWeight.w400, - fontSize: 14), - ), - Row( - mainAxisAlignment: - MainAxisAlignment.end, - children: [ - Container( - height: 30, - width: 1, - color: ColorsManager - .graysColor, - ), - Transform.scale( - scale: .8, - child: CupertinoSwitch( - value: true, - onChanged: (value) {}, - applyTheme: true, - ), - ), - ], - ) - ], - ), - const SizedBox( - height: 5, - ), - const Divider( - color: ColorsManager.graysColor, - ), - const SizedBox( - height: 5, - ), - Row( - mainAxisAlignment: - MainAxisAlignment - .spaceBetween, - children: [ - Text( - 'Executed by', - style: Theme.of(context) - .textTheme - .bodyMedium! - .copyWith( - color: ColorsManager - .textPrimaryColor, - fontWeight: - FontWeight.w400, - fontSize: 14), - ), - Text('Cloud', - style: Theme.of(context) - .textTheme - .bodyMedium! - .copyWith( - color: - ColorsManager - .textGray, - fontWeight: - FontWeight - .w400, - fontSize: 14)), - ], - ), - ], - )), - ], - ), - ), - if (context.read().isExpanded && - !isAutomation) - SizedBox( - width: 400, - height: 150, - child: state is LoadingState - ? const Center( - child: CircularProgressIndicator()) - : GridView.builder( - gridDelegate: - const SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 6, - crossAxisSpacing: 12, - mainAxisSpacing: 12, - ), - shrinkWrap: true, - itemCount: list.length, - itemBuilder: (context, index) { - final iconModel = list[index]; - return SizedBox( - width: 35, - height: 35, - child: InkWell( - onTap: () { - BlocProvider.of( - context) - .add(SelectIcon( - iconId: iconModel.uuid, - )); - selectedIcon = iconModel.uuid; - }, - child: SizedBox( - child: ClipOval( - child: Container( - padding: - const EdgeInsets.all(1), - decoration: BoxDecoration( - border: Border.all( - color: selectedIcon == - iconModel.uuid - ? ColorsManager - .primaryColorWithOpacity - : Colors - .transparent, - width: 2, - ), - shape: BoxShape.circle, - ), - child: Image.memory( - iconModel.iconBytes, - ), - ), - ), - ), - ), - ); - }, - )), - if (context.read().isExpanded && - isAutomation) - const SizedBox( - height: 350, - width: 400, - child: EffectivePeriodView()) - ], - ), - Container( - width: MediaQuery.sizeOf(context).width, - decoration: const BoxDecoration( - border: Border( - top: BorderSide( - color: ColorsManager.greyColor, - ), - ), - ), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, + content: BlocBuilder( + builder: (context, effectPeriodState) { + return BlocBuilder( + builder: (context, settingState) { + String selectedIcon = ''; + List list = []; + if (settingState is TabToRunSettingLoaded) { + selectedIcon = settingState.selectedIcon; + list = settingState.iconList; + } + return Container( + width: context.read().isExpanded ? 800 : 400, + height: context.read().isExpanded && isAutomation ? 500 : 300, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(20), + ), + padding: const EdgeInsets.only(top: 20), + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const DialogHeader('Settings'), + Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, children: [ - Expanded( - child: InkWell( - onTap: () { - Navigator.of(context).pop(); - }, - child: Container( - alignment: AlignmentDirectional.center, - child: Text( - 'Cancel', - style: Theme.of(context) - .textTheme - .bodyMedium! - .copyWith( - color: ColorsManager.textGray, - ), - ), - ), - ), - ), - Container( - width: 1, - height: 50, - color: ColorsManager.greyColor), - Expanded( - child: InkWell( - onTap: () { - Navigator.of(context).pop(selectedIcon); - }, - child: Container( - alignment: AlignmentDirectional.center, - child: Text( - 'Confirm', - style: Theme.of(context) - .textTheme - .bodyMedium! - .copyWith( - color: ColorsManager - .primaryColorWithOpacity, - ), - ), - ), - ), + SizedBox( + width: 400, + child: isAutomation + ? Column( + mainAxisSize: MainAxisSize.min, + children: [ + Container( + padding: const EdgeInsets.only( + top: 10, left: 10, right: 10, bottom: 10), + child: Column( + children: [ + InkWell( + onTap: () {}, + child: Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + Text( + 'Validity', + style: Theme.of(context) + .textTheme + .bodyMedium! + .copyWith( + color: + ColorsManager.textPrimaryColor, + fontWeight: FontWeight.w400, + fontSize: 14), + ), + const Icon( + Icons.arrow_forward_ios_outlined, + color: ColorsManager.textGray, + size: 15, + ) + ], + ), + ), + const SizedBox( + height: 5, + ), + const Divider( + color: ColorsManager.graysColor, + ), + const SizedBox( + height: 5, + ), + InkWell( + onTap: () { + BlocProvider.of(context).add( + FetchIcons( + expanded: !context + .read() + .isExpanded)); + }, + child: Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + Text( + 'Effective Period', + style: Theme.of(context) + .textTheme + .bodyMedium! + .copyWith( + color: + ColorsManager.textPrimaryColor, + fontWeight: FontWeight.w400, + fontSize: 14), + ), + const Icon( + Icons.arrow_forward_ios_outlined, + color: ColorsManager.textGray, + size: 15, + ) + ], + ), + ), + const SizedBox( + height: 5, + ), + const Divider( + color: ColorsManager.graysColor, + ), + const SizedBox( + height: 5, + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + 'Executed by', + style: Theme.of(context) + .textTheme + .bodyMedium! + .copyWith( + color: ColorsManager.textPrimaryColor, + fontWeight: FontWeight.w400, + fontSize: 14), + ), + Text('Cloud', + style: Theme.of(context) + .textTheme + .bodyMedium! + .copyWith( + color: ColorsManager.textGray, + fontWeight: FontWeight.w400, + fontSize: 14)), + ], + ), + ], + )), + ], + ) + : Column( + mainAxisSize: MainAxisSize.min, + children: [ + Container( + padding: const EdgeInsets.only( + top: 10, left: 10, right: 10, bottom: 10), + child: Column( + children: [ + InkWell( + onTap: () { + BlocProvider.of(context).add( + FetchIcons( + expanded: !context + .read() + .isExpanded)); + }, + child: Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + Text( + 'Icons', + style: Theme.of(context) + .textTheme + .bodyMedium! + .copyWith( + color: + ColorsManager.textPrimaryColor, + fontWeight: FontWeight.w400, + fontSize: 14), + ), + const Icon( + Icons.arrow_forward_ios_outlined, + color: ColorsManager.textGray, + size: 15, + ) + ], + ), + ), + const SizedBox( + height: 5, + ), + const Divider( + color: ColorsManager.graysColor, + ), + const SizedBox( + height: 5, + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + 'Show on devices page', + style: Theme.of(context) + .textTheme + .bodyMedium! + .copyWith( + color: ColorsManager.textPrimaryColor, + fontWeight: FontWeight.w400, + fontSize: 14), + ), + Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Container( + height: 30, + width: 1, + color: ColorsManager.graysColor, + ), + Transform.scale( + scale: .8, + child: CupertinoSwitch( + value: true, + onChanged: (value) {}, + applyTheme: true, + ), + ), + ], + ) + ], + ), + const SizedBox( + height: 5, + ), + const Divider( + color: ColorsManager.graysColor, + ), + const SizedBox( + height: 5, + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + 'Executed by', + style: Theme.of(context) + .textTheme + .bodyMedium! + .copyWith( + color: ColorsManager.textPrimaryColor, + fontWeight: FontWeight.w400, + fontSize: 14), + ), + Text('Cloud', + style: Theme.of(context) + .textTheme + .bodyMedium! + .copyWith( + color: ColorsManager.textGray, + fontWeight: FontWeight.w400, + fontSize: 14)), + ], + ), + ], + )), + ], + ), ), + if (context.read().isExpanded && !isAutomation) + SizedBox( + width: 400, + height: 150, + child: settingState is LoadingState + ? const Center(child: CircularProgressIndicator()) + : GridView.builder( + gridDelegate: + const SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 6, + crossAxisSpacing: 12, + mainAxisSpacing: 12, + ), + shrinkWrap: true, + itemCount: list.length, + itemBuilder: (context, index) { + final iconModel = list[index]; + return SizedBox( + width: 35, + height: 35, + child: InkWell( + onTap: () { + BlocProvider.of(context) + .add(SelectIcon( + iconId: iconModel.uuid, + )); + selectedIcon = iconModel.uuid; + }, + child: SizedBox( + child: ClipOval( + child: Container( + padding: const EdgeInsets.all(1), + decoration: BoxDecoration( + border: Border.all( + color: selectedIcon == iconModel.uuid + ? ColorsManager + .primaryColorWithOpacity + : Colors.transparent, + width: 2, + ), + shape: BoxShape.circle, + ), + child: Image.memory( + iconModel.iconBytes, + ), + ), + ), + ), + ), + ); + }, + )), + if (context.read().isExpanded && isAutomation) + const SizedBox(height: 350, width: 400, child: EffectivePeriodView()) ], ), - ) - ], - ), - ); - }, - ), + Container( + width: MediaQuery.sizeOf(context).width, + decoration: const BoxDecoration( + border: Border( + top: BorderSide( + color: ColorsManager.greyColor, + ), + ), + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: InkWell( + onTap: () { + Navigator.of(context).pop(); + }, + child: Container( + alignment: AlignmentDirectional.center, + child: Text( + 'Cancel', + style: Theme.of(context).textTheme.bodyMedium!.copyWith( + color: ColorsManager.textGray, + ), + ), + ), + ), + ), + Container(width: 1, height: 50, color: ColorsManager.greyColor), + Expanded( + child: InkWell( + onTap: () { + if (isAutomation) { + BlocProvider.of(context).add( + EffectiveTimePeriodEvent(EffectiveTime( + start: effectPeriodState.customStartTime!, + end: effectPeriodState.customEndTime!, + loops: effectPeriodState.selectedDaysBinary))); + Navigator.of(context).pop(); + } else { + Navigator.of(context).pop(selectedIcon); + } + }, + child: Container( + alignment: AlignmentDirectional.center, + child: Text( + 'Confirm', + style: Theme.of(context).textTheme.bodyMedium!.copyWith( + color: ColorsManager.primaryColorWithOpacity, + ), + ), + ), + ), + ), + ], + ), + ) + ], + ), + ); + }, + ); + }), ), ); }, diff --git a/lib/pages/routiens/widgets/routine_search_and_buttons.dart b/lib/pages/routiens/widgets/routine_search_and_buttons.dart index 5bf9db8e..f7738861 100644 --- a/lib/pages/routiens/widgets/routine_search_and_buttons.dart +++ b/lib/pages/routiens/widgets/routine_search_and_buttons.dart @@ -15,203 +15,203 @@ class RoutineSearchAndButtons extends StatelessWidget { @override Widget build(BuildContext context) { - return LayoutBuilder( - builder: (BuildContext context, BoxConstraints constraints) { - return Wrap( - runSpacing: 16, - children: [ - Row( - crossAxisAlignment: CrossAxisAlignment.end, - children: [ - Expanded( - child: Wrap( - spacing: 12, - runSpacing: 12, - crossAxisAlignment: WrapCrossAlignment.end, - children: [ - ConstrainedBox( - constraints: BoxConstraints( - maxWidth: constraints.maxWidth > 700 - ? 450 - : constraints.maxWidth - 32), - child: StatefulTextField( - title: 'Routine Name', - height: 40, - controller: TextEditingController(), - hintText: 'Please enter the name', - boxDecoration: containerWhiteDecoration, - elevation: 0, - borderRadius: 15, - isRequired: true, - width: 450, - onChanged: (value) { - context - .read() - .add(SetRoutineName(value)); - }, + return BlocBuilder(builder: (context, state) { + return LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + return Wrap( + runSpacing: 16, + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Expanded( + child: Wrap( + spacing: 12, + runSpacing: 12, + crossAxisAlignment: WrapCrossAlignment.end, + children: [ + ConstrainedBox( + constraints: BoxConstraints( + maxWidth: + constraints.maxWidth > 700 ? 450 : constraints.maxWidth - 32), + child: StatefulTextField( + title: 'Routine Name', + height: 40, + controller: TextEditingController(), + hintText: 'Please enter the name', + boxDecoration: containerWhiteDecoration, + elevation: 0, + borderRadius: 15, + isRequired: true, + width: 450, + onChanged: (value) { + context.read().add(SetRoutineName(value)); + }, + ), ), - ), - (constraints.maxWidth <= 1000) - ? const SizedBox() - : SizedBox( - height: 40, - width: 200, - child: Center( - child: DefaultButton( - onPressed: () async { - final result = - await SettingHelper.showSettingDialog( - context: context, - ); - if (result != null) { - context - .read() - .add(AddSelectedIcon(result)); - } - }, - borderRadius: 15, - elevation: 0, - borderColor: ColorsManager.greyColor, - backgroundColor: ColorsManager.boxColor, - child: const Text( - 'Settings', - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 12, - color: ColorsManager.primaryColor, + (constraints.maxWidth <= 1000) + ? const SizedBox() + : SizedBox( + height: 40, + width: 200, + child: Center( + child: DefaultButton( + onPressed: state.isAutomation || state.isTabToRun + ? () async { + final result = await SettingHelper.showSettingDialog( + context: context, + ); + if (result != null) { + context + .read() + .add(AddSelectedIcon(result)); + } + } + : null, + borderRadius: 15, + elevation: 0, + borderColor: ColorsManager.greyColor, + backgroundColor: ColorsManager.boxColor, + child: const Text( + 'Settings', + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 12, + color: ColorsManager.primaryColor, + ), ), ), ), ), - ), - ], + ], + ), ), - ), - if (constraints.maxWidth > 1000) - Row( - mainAxisSize: MainAxisSize.min, - children: [ - SizedBox( - height: 40, - width: 200, - child: Center( - child: DefaultButton( - onPressed: () {}, - borderRadius: 15, - elevation: 0, - borderColor: ColorsManager.greyColor, - backgroundColor: ColorsManager.boxColor, - child: const Text( - 'Cancel', - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 12, - color: ColorsManager.blackColor, + if (constraints.maxWidth > 1000) + Row( + mainAxisSize: MainAxisSize.min, + children: [ + SizedBox( + height: 40, + width: 200, + child: Center( + child: DefaultButton( + onPressed: () {}, + borderRadius: 15, + elevation: 0, + borderColor: ColorsManager.greyColor, + backgroundColor: ColorsManager.boxColor, + child: const Text( + 'Cancel', + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 12, + color: ColorsManager.blackColor, + ), ), ), ), ), - ), - const SizedBox(width: 12), - SizedBox( - height: 40, - width: 200, - child: Center( - child: DefaultButton( - onPressed: () { - SaveRoutineHelper.showSaveRoutineDialog(context); - }, - borderRadius: 15, - elevation: 0, - backgroundColor: ColorsManager.primaryColor, - child: const Text( - 'Save', - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 12, - color: ColorsManager.whiteColors, + const SizedBox(width: 12), + SizedBox( + height: 40, + width: 200, + child: Center( + child: DefaultButton( + onPressed: () { + SaveRoutineHelper.showSaveRoutineDialog(context); + }, + borderRadius: 15, + elevation: 0, + backgroundColor: ColorsManager.primaryColor, + child: const Text( + 'Save', + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 12, + color: ColorsManager.whiteColors, + ), ), ), ), ), - ), - ], - ), - ], - ), - if (constraints.maxWidth <= 1000) - Wrap( - runSpacing: 12, - children: [ - SizedBox( - height: 40, - width: 200, - child: Center( - child: DefaultButton( - onPressed: () {}, - borderRadius: 15, - elevation: 0, - borderColor: ColorsManager.greyColor, - backgroundColor: ColorsManager.boxColor, - child: const Text( - 'Settings', - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 12, - color: ColorsManager.primaryColor, - ), - ), - ), + ], ), - ), - const SizedBox(width: 12), - SizedBox( - height: 40, - width: 200, - child: Center( - child: DefaultButton( - onPressed: () {}, - borderRadius: 15, - elevation: 0, - borderColor: ColorsManager.greyColor, - backgroundColor: ColorsManager.boxColor, - child: const Text( - 'Cancel', - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 12, - color: ColorsManager.blackColor, - ), - ), - ), - ), - ), - const SizedBox(width: 12), - SizedBox( - height: 40, - width: 200, - child: Center( - child: DefaultButton( - onPressed: () {}, - borderRadius: 15, - elevation: 0, - backgroundColor: ColorsManager.primaryColor, - child: const Text( - 'Save', - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 12, - color: ColorsManager.whiteColors, - ), - ), - ), - ), - ), ], ), - ], - ); - }, - ); + if (constraints.maxWidth <= 1000) + Wrap( + runSpacing: 12, + children: [ + SizedBox( + height: 40, + width: 200, + child: Center( + child: DefaultButton( + onPressed: () {}, + borderRadius: 15, + elevation: 0, + borderColor: ColorsManager.greyColor, + backgroundColor: ColorsManager.boxColor, + child: const Text( + 'Settings', + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 12, + color: ColorsManager.primaryColor, + ), + ), + ), + ), + ), + const SizedBox(width: 12), + SizedBox( + height: 40, + width: 200, + child: Center( + child: DefaultButton( + onPressed: () {}, + borderRadius: 15, + elevation: 0, + borderColor: ColorsManager.greyColor, + backgroundColor: ColorsManager.boxColor, + child: const Text( + 'Cancel', + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 12, + color: ColorsManager.blackColor, + ), + ), + ), + ), + ), + const SizedBox(width: 12), + SizedBox( + height: 40, + width: 200, + child: Center( + child: DefaultButton( + onPressed: () {}, + borderRadius: 15, + elevation: 0, + backgroundColor: ColorsManager.primaryColor, + child: const Text( + 'Save', + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 12, + color: ColorsManager.whiteColors, + ), + ), + ), + ), + ), + ], + ), + ], + ); + }, + ); + }); } } diff --git a/lib/pages/routiens/widgets/then_container.dart b/lib/pages/routiens/widgets/then_container.dart index 9d729327..52749851 100644 --- a/lib/pages/routiens/widgets/then_container.dart +++ b/lib/pages/routiens/widgets/then_container.dart @@ -26,9 +26,7 @@ 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, @@ -37,16 +35,12 @@ class ThenContainer extends StatelessWidget { state.thenItems.length, (index) => GestureDetector( onTap: () async { - if (state.thenItems[index]['deviceId'] == - 'delay') { - final result = await DelayHelper - .showDelayPickerDialog( - context, state.thenItems[index]); + if (state.thenItems[index]['deviceId'] == 'delay') { + final result = await DelayHelper.showDelayPickerDialog( + context, state.thenItems[index]); if (result != null) { - context - .read() - .add(AddToThenContainer({ + context.read().add(AddToThenContainer({ ...state.thenItems[index], 'imagePath': Assets.delay, 'title': 'Delay', @@ -55,37 +49,32 @@ class ThenContainer extends StatelessWidget { return; } - final result = await DeviceDialogHelper - .showDeviceDialog( - context, state.thenItems[index]); + final result = await DeviceDialogHelper.showDeviceDialog( + context, state.thenItems[index]); if (result != null) { - context.read().add( - AddToThenContainer( - state.thenItems[index])); + context + .read() + .add(AddToThenContainer(state.thenItems[index])); } else if (!['AC', '1G', '2G', '3G'] - .contains(state.thenItems[index] - ['productType'])) { - context.read().add( - AddToThenContainer( - state.thenItems[index])); + .contains(state.thenItems[index]['productType'])) { + context + .read() + .add(AddToThenContainer(state.thenItems[index])); } }, child: DraggableCard( - imagePath: state.thenItems[index] - ['imagePath'] ?? - '', - title: - state.thenItems[index]['title'] ?? '', + imagePath: state.thenItems[index]['imagePath'] ?? '', + title: state.thenItems[index]['title'] ?? '', deviceData: state.thenItems[index], - padding: const EdgeInsets.symmetric( - horizontal: 4, vertical: 8), + padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 8), isFromThen: true, isFromIf: false, onRemove: () { - context.read().add( - RemoveDragCard( - index: index, isFromThen: true)); + context.read().add(RemoveDragCard( + index: index, + isFromThen: true, + key: state.thenItems[index]['uniqueCustomId'])); }, ), ))), @@ -140,8 +129,7 @@ class ThenContainer extends StatelessWidget { } if (mutableData['deviceId'] == 'delay') { - final result = - await DelayHelper.showDelayPickerDialog(context, mutableData); + final result = await DelayHelper.showDelayPickerDialog(context, mutableData); if (result != null) { context.read().add(AddToThenContainer({ @@ -153,13 +141,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().add(AddToThenContainer(mutableData)); - } else if (!['AC', '1G', '2G', '3G'] - .contains(mutableData['productType'])) { + } else if (!['AC', '1G', '2G', '3G'].contains(mutableData['productType'])) { context.read().add(AddToThenContainer(mutableData)); } },