mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
push adding the selected functiond and device to then container
This commit is contained in:
@ -15,7 +15,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
on<AddToThenContainer>(_onAddToThenContainer);
|
||||
on<LoadScenes>(_onLoadScenes);
|
||||
on<LoadAutomation>(_onLoadAutomation);
|
||||
on<AddFunction>(_onAddFunction);
|
||||
on<AddFunctionToRoutine>(_onAddFunction);
|
||||
on<RemoveFunction>(_onRemoveFunction);
|
||||
on<ClearFunctions>(_onClearFunctions);
|
||||
}
|
||||
@ -37,7 +37,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _onAddFunction(AddFunction event, Emitter<RoutineState> emit) {
|
||||
void _onAddFunction(AddFunctionToRoutine event, Emitter<RoutineState> emit) {
|
||||
final functions = List<DeviceFunctionData>.from(state.selectedFunctions);
|
||||
functions.add(event.function);
|
||||
emit(state.copyWith(selectedFunctions: functions));
|
||||
|
@ -43,9 +43,9 @@ class LoadAutomation extends RoutineEvent {
|
||||
List<Object> get props => [unitId];
|
||||
}
|
||||
|
||||
class AddFunction extends RoutineEvent {
|
||||
class AddFunctionToRoutine extends RoutineEvent {
|
||||
final DeviceFunctionData function;
|
||||
const AddFunction(this.function);
|
||||
const AddFunctionToRoutine(this.function);
|
||||
@override
|
||||
List<Object> get props => [function];
|
||||
}
|
||||
|
@ -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<FunctionBloc, FunctionBlocState>(
|
||||
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<RoutineBloc>().add(
|
||||
AddFunctionToRoutine(
|
||||
function,
|
||||
),
|
||||
);
|
||||
}
|
||||
// Return the device data to be added to the container
|
||||
Navigator.pop(context);
|
||||
}
|
||||
: null,
|
||||
isConfirmEnabled: selectedFunction != null,
|
||||
),
|
||||
|
@ -13,11 +13,15 @@ class DeviceDialogHelper {
|
||||
final functions = data['functions'] as List<DeviceFunction>;
|
||||
|
||||
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<void> _getDialogForDeviceType(
|
||||
static Future<Map<String, dynamic>?> _getDialogForDeviceType(
|
||||
BuildContext context,
|
||||
String productType,
|
||||
List<DeviceFunction> 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;
|
||||
}
|
||||
|
@ -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<void> showSwitchFunctionsDialog(
|
||||
static Future<Map<String, dynamic>?> showSwitchFunctionsDialog(
|
||||
BuildContext context, List<DeviceFunction<dynamic>> functions) async {
|
||||
List<DeviceFunction<dynamic>> switchFunctions = functions
|
||||
.where((f) =>
|
||||
|
@ -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<void> showSwitchFunctionsDialog(
|
||||
static Future<Map<String, dynamic>?> showSwitchFunctionsDialog(
|
||||
BuildContext context, List<DeviceFunction<dynamic>> functions) async {
|
||||
List<DeviceFunction<dynamic>> switchFunctions = functions
|
||||
.where((f) =>
|
||||
|
@ -46,7 +46,7 @@ class ThenContainer extends StatelessWidget {
|
||||
final result =
|
||||
await DeviceDialogHelper.showDeviceDialog(context, data);
|
||||
if (result != null) {
|
||||
context.read<RoutineBloc>().add(AddToThenContainer(result));
|
||||
context.read<RoutineBloc>().add(AddToThenContainer(data));
|
||||
} else if (!['AC', '1G', '2G', '3G']
|
||||
.contains(data['productType'])) {
|
||||
context.read<RoutineBloc>().add(AddToThenContainer(data));
|
||||
|
Reference in New Issue
Block a user