diff --git a/lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart b/lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart index d69df552..20a3c393 100644 --- a/lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart +++ b/lib/pages/routiens/bloc/routine_bloc/routine_bloc.dart @@ -15,7 +15,7 @@ class RoutineBloc extends Bloc { on(_onAddToThenContainer); on(_onLoadScenes); on(_onLoadAutomation); - on(_onAddFunction); + on(_onAddFunction); on(_onRemoveFunction); on(_onClearFunctions); } @@ -37,7 +37,7 @@ class RoutineBloc extends Bloc { } } - void _onAddFunction(AddFunction event, Emitter emit) { + void _onAddFunction(AddFunctionToRoutine event, Emitter emit) { final functions = List.from(state.selectedFunctions); functions.add(event.function); emit(state.copyWith(selectedFunctions: functions)); diff --git a/lib/pages/routiens/bloc/routine_bloc/routine_event.dart b/lib/pages/routiens/bloc/routine_bloc/routine_event.dart index d3af8134..3321af5e 100644 --- a/lib/pages/routiens/bloc/routine_bloc/routine_event.dart +++ b/lib/pages/routiens/bloc/routine_bloc/routine_event.dart @@ -43,9 +43,9 @@ class LoadAutomation extends RoutineEvent { List get props => [unitId]; } -class AddFunction extends RoutineEvent { +class AddFunctionToRoutine extends RoutineEvent { final DeviceFunctionData function; - const AddFunction(this.function); + const AddFunctionToRoutine(this.function); @override List get props => [function]; } diff --git a/lib/pages/routiens/helper/ac_helper.dart b/lib/pages/routiens/helper/ac_helper.dart index 327d0787..4a42c43d 100644 --- a/lib/pages/routiens/helper/ac_helper.dart +++ b/lib/pages/routiens/helper/ac_helper.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; +import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart'; import 'package:syncrow_web/pages/routiens/models/ac/ac_function.dart'; import 'package:syncrow_web/pages/routiens/models/device_functions.dart'; import 'package:syncrow_web/pages/routiens/widgets/dialog_footer.dart'; @@ -36,9 +37,6 @@ class ACHelper { contentPadding: EdgeInsets.zero, content: BlocBuilder( builder: (context, state) { - debugPrint( - 'Current state - Selected: ${state.selectedFunction}, Functions: ${state.functions}'); - final selectedFunction = state.selectedFunction; final selectedFunctionData = selectedFunction != null ? state.functions.firstWhere( @@ -118,7 +116,18 @@ class ACHelper { }, onConfirm: selectedFunction != null && selectedFunctionData?.value != null - ? () {} + ? () { + /// add the functions to the routine bloc + for (var function in state.functions) { + context.read().add( + AddFunctionToRoutine( + function, + ), + ); + } + // Return the device data to be added to the container + Navigator.pop(context); + } : null, isConfirmEnabled: selectedFunction != null, ), diff --git a/lib/pages/routiens/helper/dialog_helper/device_dialog_helper.dart b/lib/pages/routiens/helper/dialog_helper/device_dialog_helper.dart index ea4743b7..2b21d83d 100644 --- a/lib/pages/routiens/helper/dialog_helper/device_dialog_helper.dart +++ b/lib/pages/routiens/helper/dialog_helper/device_dialog_helper.dart @@ -13,11 +13,15 @@ class DeviceDialogHelper { final functions = data['functions'] as List; try { - await _getDialogForDeviceType( + final result = await _getDialogForDeviceType( context, data['productType'], functions, ); + + if (result != null) { + return result; + } } catch (e) { debugPrint('Error: $e'); } @@ -25,23 +29,22 @@ class DeviceDialogHelper { return null; } - static Future _getDialogForDeviceType( + static Future?> _getDialogForDeviceType( BuildContext context, String productType, List functions, ) async { switch (productType) { case 'AC': - await ACHelper.showACFunctionsDialog(context, functions); - break; + return ACHelper.showACFunctionsDialog(context, functions); case '1G': - await OneGangSwitchHelper.showSwitchFunctionsDialog(context, functions); - break; + return OneGangSwitchHelper.showSwitchFunctionsDialog( + context, functions); case '2G': - await TwoGangSwitchHelper.showSwitchFunctionsDialog(context, functions); - break; + return TwoGangSwitchHelper.showSwitchFunctionsDialog( + context, functions); case '3G': - await ThreeGangSwitchHelper.showSwitchFunctionsDialog( + return ThreeGangSwitchHelper.showSwitchFunctionsDialog( context, functions); break; } diff --git a/lib/pages/routiens/helper/three_gang_switch_helper.dart b/lib/pages/routiens/helper/three_gang_switch_helper.dart index 1e62f5c4..ecbe81f2 100644 --- a/lib/pages/routiens/helper/three_gang_switch_helper.dart +++ b/lib/pages/routiens/helper/three_gang_switch_helper.dart @@ -9,7 +9,7 @@ import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/extension/build_context_x.dart'; class ThreeGangSwitchHelper { - static Future showSwitchFunctionsDialog( + static Future?> showSwitchFunctionsDialog( BuildContext context, List> functions) async { List> switchFunctions = functions .where((f) => diff --git a/lib/pages/routiens/helper/two_gang_switch_helper.dart b/lib/pages/routiens/helper/two_gang_switch_helper.dart index 8a7e5580..f0e3026a 100644 --- a/lib/pages/routiens/helper/two_gang_switch_helper.dart +++ b/lib/pages/routiens/helper/two_gang_switch_helper.dart @@ -9,7 +9,7 @@ import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/extension/build_context_x.dart'; class TwoGangSwitchHelper { - static Future showSwitchFunctionsDialog( + static Future?> showSwitchFunctionsDialog( BuildContext context, List> functions) async { List> switchFunctions = functions .where((f) => diff --git a/lib/pages/routiens/widgets/then_container.dart b/lib/pages/routiens/widgets/then_container.dart index e4df6d8b..633a1ad1 100644 --- a/lib/pages/routiens/widgets/then_container.dart +++ b/lib/pages/routiens/widgets/then_container.dart @@ -46,7 +46,7 @@ class ThenContainer extends StatelessWidget { final result = await DeviceDialogHelper.showDeviceDialog(context, data); if (result != null) { - context.read().add(AddToThenContainer(result)); + context.read().add(AddToThenContainer(data)); } else if (!['AC', '1G', '2G', '3G'] .contains(data['productType'])) { context.read().add(AddToThenContainer(data));