diff --git a/lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart b/lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart index d857de76..9186cc78 100644 --- a/lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart +++ b/lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart @@ -363,11 +363,20 @@ class RoutineBloc extends Bloc { ifItems.removeAt(event.index); selectedFunctions.remove(event.key); - emit(state.copyWith(ifItems: ifItems, selectedFunctions: selectedFunctions)); + if (ifItems.isEmpty && state.thenItems.isEmpty) { + emit(state.copyWith( + ifItems: ifItems, + selectedFunctions: selectedFunctions, + isAutomation: false, + isTabToRun: false)); + } else { + emit(state.copyWith(ifItems: ifItems, selectedFunctions: selectedFunctions)); + } } } - FutureOr _changeOperatorOperator(ChangeAutomationOperator event, Emitter emit) { + FutureOr _changeOperatorOperator( + ChangeAutomationOperator event, Emitter emit) { emit(state.copyWith( selectedAutomationOperator: event.operator, )); @@ -396,7 +405,7 @@ class RoutineBloc extends Bloc { selectedIcon: null, isTabToRun: false, isAutomation: false, - selectedAutomationOperator: 'AND', + selectedAutomationOperator: 'or', effectiveTime: null, routineName: null, ); diff --git a/lib/pages/routiens/widgets/if_container.dart b/lib/pages/routiens/widgets/if_container.dart index d0273adc..da2b540b 100644 --- a/lib/pages/routiens/widgets/if_container.dart +++ b/lib/pages/routiens/widgets/if_container.dart @@ -27,7 +27,7 @@ class IfContainer extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ const Text('IF', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), - if (state.isAutomation) + if (state.isAutomation && state.ifItems.isNotEmpty) AutomationOperatorSelector( selectedOperator: state.selectedAutomationOperator), ], @@ -88,13 +88,16 @@ class IfContainer extends StatelessWidget { ), ); }, - onWillAccept: (data) => data != null, - onAccept: (data) async { + onAcceptWithDetails: (data) async { final uniqueCustomId = const Uuid().v4(); - final mutableData = Map.from(data); + final mutableData = Map.from(data.data); mutableData['uniqueCustomId'] = uniqueCustomId; + if (state.isAutomation && mutableData['deviceId'] == 'tab_to_run') { + return; + } + if (!state.isTabToRun) { if (mutableData['deviceId'] == 'tab_to_run') { context.read().add(AddToIfContainer(mutableData, true)); @@ -134,7 +137,7 @@ class AutomationOperatorSelector extends StatelessWidget { children: [ TextButton( style: TextButton.styleFrom( - backgroundColor: selectedOperator == 'or' + backgroundColor: selectedOperator.toLowerCase() == 'or' ? ColorsManager.dialogBlueTitle : ColorsManager.whiteColors, shape: RoundedRectangleBorder( @@ -144,8 +147,9 @@ class AutomationOperatorSelector extends StatelessWidget { child: Text( 'Any condition is met', style: context.textTheme.bodyMedium?.copyWith( - color: - selectedOperator == 'or' ? ColorsManager.whiteColors : ColorsManager.blackColor, + color: selectedOperator.toLowerCase() == 'or' + ? ColorsManager.whiteColors + : ColorsManager.blackColor, ), ), onPressed: () { @@ -159,7 +163,7 @@ class AutomationOperatorSelector extends StatelessWidget { ), TextButton( style: TextButton.styleFrom( - backgroundColor: selectedOperator == 'and' + backgroundColor: selectedOperator.toLowerCase() == 'and' ? ColorsManager.dialogBlueTitle : ColorsManager.whiteColors, shape: RoundedRectangleBorder( @@ -169,7 +173,7 @@ class AutomationOperatorSelector extends StatelessWidget { child: Text( 'All condition is met', style: context.textTheme.bodyMedium?.copyWith( - color: selectedOperator == 'and' + color: selectedOperator.toLowerCase() == 'and' ? ColorsManager.whiteColors : ColorsManager.blackColor, ), diff --git a/lib/pages/routiens/widgets/period_option.dart b/lib/pages/routiens/widgets/period_option.dart index 5c1c2d51..1871ebda 100644 --- a/lib/pages/routiens/widgets/period_option.dart +++ b/lib/pages/routiens/widgets/period_option.dart @@ -75,7 +75,11 @@ class PeriodOptions extends StatelessWidget { onTap: () { context.read().add(SetPeriod(value)); }, - title: Text(EffectPeriodHelper.formatEnumValue(value)), + title: Text( + EffectPeriodHelper.formatEnumValue(value), + style: Theme.of(context).textTheme.bodyMedium!.copyWith( + color: ColorsManager.blackColor, fontWeight: FontWeight.w400, fontSize: 12), + ), subtitle: Text( subtitle, style: Theme.of(context).textTheme.bodyMedium!.copyWith( diff --git a/lib/pages/routiens/widgets/then_container.dart b/lib/pages/routiens/widgets/then_container.dart index 52749851..8dbc5904 100644 --- a/lib/pages/routiens/widgets/then_container.dart +++ b/lib/pages/routiens/widgets/then_container.dart @@ -128,6 +128,20 @@ class ThenContainer extends StatelessWidget { return; } + if (mutableData['type'] == 'tap_to_run' && state.isAutomation) { + context.read().add(AddToThenContainer({ + ...mutableData, + 'imagePath': Assets.loginLogo, + 'title': mutableData['name'], + })); + + return; + } + + if (mutableData['type'] == 'tap_to_run' && !state.isAutomation) { + return; + } + if (mutableData['deviceId'] == 'delay') { final result = await DelayHelper.showDelayPickerDialog(context, mutableData); @@ -142,7 +156,6 @@ class ThenContainer extends StatelessWidget { } final result = await DeviceDialogHelper.showDeviceDialog(context, mutableData); - if (result != null) { context.read().add(AddToThenContainer(mutableData)); } else if (!['AC', '1G', '2G', '3G'].contains(mutableData['productType'])) {