mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
Add CpsDialogSliderSelector for enhanced slider functionality and integrate with CeilingSensorDialog
This commit is contained in:
@ -7,6 +7,8 @@ import 'package:syncrow_web/pages/routines/models/ceiling_presence_sensor_functi
|
||||
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/dialog_footer.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/dialog_header.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/ceiling_sensor/ceiling_sensor_helper.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/ceiling_sensor/cps_dialog_slider_selector.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/ceiling_sensor/cps_dialog_value_selector.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/ceiling_sensor/cps_functions_list.dart';
|
||||
|
||||
@ -122,21 +124,32 @@ class _CeilingSensorDialogState extends State<CeilingSensorDialog> {
|
||||
),
|
||||
);
|
||||
final operations = selectedCpsFunctions.getOperationalValues();
|
||||
|
||||
final isToggleFunction =
|
||||
CeilingSensorHelper.toggleCodes.contains(selectedFunction);
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
CpsFunctionsList(cpsFunctions: _cpsFunctions),
|
||||
if (state.selectedFunction != null)
|
||||
Expanded(
|
||||
child: CpsDialogValueSelector(
|
||||
operations: operations,
|
||||
selectedFunction: selectedFunction ?? '',
|
||||
selectedFunctionData: selectedFunctionData,
|
||||
cpsFunctions: _cpsFunctions,
|
||||
operationName: selectedOperationName ?? '',
|
||||
device: widget.device,
|
||||
),
|
||||
child: isToggleFunction
|
||||
? CpsDialogValueSelector(
|
||||
operations: operations,
|
||||
selectedFunction: selectedFunction ?? '',
|
||||
selectedFunctionData: selectedFunctionData,
|
||||
cpsFunctions: _cpsFunctions,
|
||||
operationName: selectedOperationName ?? '',
|
||||
device: widget.device,
|
||||
)
|
||||
: CpsDialogSliderSelector(
|
||||
operations: operations,
|
||||
selectedFunction: selectedFunction ?? '',
|
||||
selectedFunctionData: selectedFunctionData,
|
||||
cpsFunctions: _cpsFunctions,
|
||||
operationName: selectedOperationName ?? '',
|
||||
device: widget.device,
|
||||
dialogType: widget.dialogType,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
@ -0,0 +1,105 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
||||
import 'package:syncrow_web/pages/routines/bloc/functions_bloc/functions_bloc_bloc.dart';
|
||||
import 'package:syncrow_web/pages/routines/models/ceiling_presence_sensor_functions.dart';
|
||||
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/slider_value_selector.dart';
|
||||
|
||||
class CpsDialogSliderSelector extends StatelessWidget {
|
||||
const CpsDialogSliderSelector({
|
||||
required this.operations,
|
||||
required this.selectedFunction,
|
||||
required this.selectedFunctionData,
|
||||
required this.cpsFunctions,
|
||||
required this.device,
|
||||
required this.operationName,
|
||||
required this.dialogType,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final List<CpsOperationalValue> operations;
|
||||
final String selectedFunction;
|
||||
final DeviceFunctionData selectedFunctionData;
|
||||
final List<CpsFunctions> cpsFunctions;
|
||||
final AllDevicesModel? device;
|
||||
final String operationName;
|
||||
final String dialogType;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SliderValueSelector(
|
||||
selectedFunction: selectedFunction,
|
||||
functionData: selectedFunctionData,
|
||||
device: device,
|
||||
dialogType: dialogType,
|
||||
sliderRange: _sliderRange,
|
||||
displayedValue: _displayText,
|
||||
initialValue: selectedFunctionData.value ?? 0,
|
||||
onConditionChanged: (condition) => context.read<FunctionBloc>().add(
|
||||
AddFunction(
|
||||
functionData: DeviceFunctionData(
|
||||
entityId: device?.uuid ?? '',
|
||||
functionCode: selectedFunction,
|
||||
operationName: selectedFunctionData.operationName,
|
||||
condition: condition,
|
||||
value: selectedFunctionData.value,
|
||||
),
|
||||
),
|
||||
),
|
||||
onSliderChanged: (value) => context.read<FunctionBloc>().add(
|
||||
AddFunction(
|
||||
functionData: DeviceFunctionData(
|
||||
entityId: device?.uuid ?? '',
|
||||
functionCode: selectedFunction,
|
||||
operationName: selectedFunctionData.operationName,
|
||||
value: value.toInt(),
|
||||
condition: selectedFunctionData.condition,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
double get sliderStepper {
|
||||
return 1;
|
||||
}
|
||||
|
||||
(double, double) get _sliderRange => switch (selectedFunctionData.functionCode) {
|
||||
'moving_speed' => (0, 32),
|
||||
'space_static_val' => (0, 255),
|
||||
'space_move_val' => (0, 255),
|
||||
'moving_max_dis' => (0, 10),
|
||||
'static_max_dis' => (0, 10),
|
||||
'moving_range' => (0, 25.5),
|
||||
'presence_range' => (0, 25.5),
|
||||
'presence_judgement_threshold' => (0, 255),
|
||||
'motion_amplitude_trigger_threshold' => (0, 255),
|
||||
'perceptual_boundary' => (0, 5),
|
||||
'moving_boundary' => (0, 5),
|
||||
'moving_rigger_time' => (0, 2),
|
||||
'moving_static_time' => (0, 50),
|
||||
'none_body_time' => (0, 300),
|
||||
_ => (0, 300),
|
||||
};
|
||||
|
||||
String get _displayText {
|
||||
final value = selectedFunctionData.value;
|
||||
final parsedValue = double.tryParse('$value') ?? value;
|
||||
|
||||
return switch (selectedFunctionData.functionCode) {
|
||||
'moving_max_dis' ||
|
||||
'static_max_dis' ||
|
||||
'moving_range' ||
|
||||
'presence_range' ||
|
||||
'perceptual_boundary' ||
|
||||
'moving_boundary' =>
|
||||
'${parsedValue?.toStringAsFixed(1) ?? '0'} M',
|
||||
'moving_rigger_time' => '${parsedValue?.toStringAsFixed(3) ?? '0'} s',
|
||||
'moving_static_time' ||
|
||||
'none_body_time' =>
|
||||
'${parsedValue?.toStringAsFixed(0) ?? '0'} s',
|
||||
_ => '${parsedValue ?? 0}',
|
||||
};
|
||||
}
|
||||
}
|
@ -46,20 +46,8 @@ class SliderValueSelector extends StatelessWidget {
|
||||
const SizedBox(height: 20),
|
||||
FunctionSlider(
|
||||
initialValue: initialValue,
|
||||
range: sliderRange, onChanged: onSliderChanged,
|
||||
// void _updateValue(BuildContext context, int value) {
|
||||
// context.read<FunctionBloc>().add(
|
||||
// AddFunction(
|
||||
// functionData: DeviceFunctionData(
|
||||
// entityId: device?.uuid ?? '',
|
||||
// functionCode: functionCode,
|
||||
// operationName: functionData.operationName,
|
||||
// value: value,
|
||||
// condition: functionData.condition,
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
range: sliderRange,
|
||||
onChanged: onSliderChanged,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
Reference in New Issue
Block a user