mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
SP-1364/ Gateway Conditions Popup (for “If” section)
This commit is contained in:
@ -320,17 +320,17 @@ SOS
|
||||
GatewaySwitchAlarmSound(
|
||||
deviceId: uuid ?? '',
|
||||
deviceName: name ?? '',
|
||||
type: 'IF',
|
||||
type: 'BOTH',
|
||||
),
|
||||
GatewayMasterState(
|
||||
deviceId: uuid ?? '',
|
||||
deviceName: name ?? '',
|
||||
type: 'IF',
|
||||
type: 'BOTH',
|
||||
),
|
||||
GatewayFactoryReset(
|
||||
deviceId: uuid ?? '',
|
||||
deviceName: name ?? '',
|
||||
type: 'IF',
|
||||
type: 'BOTH',
|
||||
),
|
||||
];
|
||||
default:
|
||||
|
@ -33,7 +33,7 @@ final class GatewaySwitchAlarmSound extends GatewayFunctions {
|
||||
required super.deviceId,
|
||||
required super.deviceName,
|
||||
required super.type,
|
||||
super.code = '',
|
||||
super.code = 'switch_alarm_sound',
|
||||
super.operationName = 'Switch Alarm Sound',
|
||||
super.icon = Assets.activeBell,
|
||||
});
|
||||
@ -58,7 +58,7 @@ final class GatewayMasterState extends GatewayFunctions {
|
||||
required super.deviceId,
|
||||
required super.deviceName,
|
||||
required super.type,
|
||||
super.code = '',
|
||||
super.code = 'master_state',
|
||||
super.operationName = 'Master State',
|
||||
super.icon = Assets.gear,
|
||||
});
|
||||
@ -69,12 +69,12 @@ final class GatewayMasterState extends GatewayFunctions {
|
||||
GatewayOperationalValue(
|
||||
icon: Assets.assetsAcPower,
|
||||
description: "Normal",
|
||||
value: true,
|
||||
value: 'Normal',
|
||||
),
|
||||
GatewayOperationalValue(
|
||||
icon: Assets.assetsAcPowerOFF,
|
||||
description: "Alarm",
|
||||
value: false,
|
||||
value: 'Alarm',
|
||||
),
|
||||
];
|
||||
}
|
||||
@ -85,7 +85,7 @@ final class GatewayFactoryReset extends GatewayFunctions {
|
||||
required super.deviceId,
|
||||
required super.deviceName,
|
||||
required super.type,
|
||||
super.code = '',
|
||||
super.code = 'factory_reset',
|
||||
super.operationName = 'Factory Reset',
|
||||
super.icon = Assets.factoryReset,
|
||||
});
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/svg.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/bloc/routine_bloc/routine_bloc.dart';
|
||||
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
|
||||
@ -32,10 +33,7 @@ class _GatewayIfDialogState extends State<GatewayIfDialog> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_gatewayFunctions = widget.functions
|
||||
.whereType<GatewayFunctions>()
|
||||
.where((function) => function.type == 'IF' || function.type == 'BOTH')
|
||||
.toList();
|
||||
_gatewayFunctions = widget.functions.whereType<GatewayFunctions>().toList();
|
||||
}
|
||||
|
||||
@override
|
||||
@ -89,11 +87,32 @@ class _GatewayIfDialogState extends State<GatewayIfDialog> {
|
||||
}
|
||||
|
||||
Widget _buildMainContent(BuildContext context, FunctionBlocState state) {
|
||||
final selectedFunction = state.selectedFunction;
|
||||
final selectedOperationName = state.selectedOperationName;
|
||||
final selectedFunctionData = state.addedFunctions.firstWhere(
|
||||
(f) => f.functionCode == selectedFunction,
|
||||
orElse: () => DeviceFunctionData(
|
||||
entityId: '',
|
||||
functionCode: selectedFunction ?? '',
|
||||
operationName: '',
|
||||
value: null,
|
||||
),
|
||||
);
|
||||
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildFunctionList(context),
|
||||
// if (state.selectedFunction != null) _buildValueSelector(context, state),
|
||||
if (state.selectedFunction != null)
|
||||
Expanded(
|
||||
child: _buildValueSelector(
|
||||
context: context,
|
||||
selectedFunction: selectedFunction ?? '',
|
||||
selectedFunctionData: selectedFunctionData,
|
||||
acFunctions: _gatewayFunctions,
|
||||
operationName: selectedOperationName ?? '',
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
@ -103,7 +122,6 @@ class _GatewayIfDialogState extends State<GatewayIfDialog> {
|
||||
width: 360,
|
||||
child: ListView.separated(
|
||||
shrinkWrap: false,
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
itemCount: _gatewayFunctions.length,
|
||||
separatorBuilder: (context, index) => const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 40.0),
|
||||
@ -141,4 +159,85 @@ class _GatewayIfDialogState extends State<GatewayIfDialog> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
static Widget _buildValueSelector({
|
||||
required BuildContext context,
|
||||
required String selectedFunction,
|
||||
required DeviceFunctionData? selectedFunctionData,
|
||||
required List<GatewayFunctions> acFunctions,
|
||||
AllDevicesModel? device,
|
||||
required String operationName,
|
||||
}) {
|
||||
final selectedGatewayFunctions = acFunctions.firstWhere(
|
||||
(f) => f.code == selectedFunction,
|
||||
);
|
||||
final values = selectedGatewayFunctions.getOperationalValues();
|
||||
|
||||
return _buildOperationalValuesList(
|
||||
context: context,
|
||||
values: values,
|
||||
selectedValue: selectedFunctionData?.value,
|
||||
device: device,
|
||||
operationName: operationName,
|
||||
selectCode: selectedFunction,
|
||||
selectedFunctionData: selectedFunctionData,
|
||||
);
|
||||
}
|
||||
|
||||
static Widget _buildOperationalValuesList({
|
||||
required BuildContext context,
|
||||
required List<GatewayOperationalValue> values,
|
||||
required dynamic selectedValue,
|
||||
AllDevicesModel? device,
|
||||
required String operationName,
|
||||
required String selectCode,
|
||||
DeviceFunctionData? selectedFunctionData,
|
||||
}) {
|
||||
return ListView.builder(
|
||||
itemCount: values.length,
|
||||
itemBuilder: (context, index) {
|
||||
final value = values[index];
|
||||
final isSelected = selectedValue == value.value;
|
||||
return ListTile(
|
||||
leading: SvgPicture.asset(
|
||||
value.icon,
|
||||
width: 24,
|
||||
height: 24,
|
||||
placeholderBuilder: (context) => Container(
|
||||
width: 24,
|
||||
height: 24,
|
||||
color: Colors.transparent,
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
value.description,
|
||||
style: context.textTheme.bodyMedium,
|
||||
),
|
||||
trailing: Icon(
|
||||
isSelected ? Icons.radio_button_checked : Icons.radio_button_unchecked,
|
||||
size: 24,
|
||||
color: isSelected
|
||||
? ColorsManager.primaryColorWithOpacity
|
||||
: ColorsManager.textGray,
|
||||
),
|
||||
onTap: () {
|
||||
if (!isSelected) {
|
||||
context.read<FunctionBloc>().add(
|
||||
AddFunction(
|
||||
functionData: DeviceFunctionData(
|
||||
entityId: device?.uuid ?? '',
|
||||
functionCode: selectCode,
|
||||
operationName: operationName,
|
||||
value: value.value,
|
||||
condition: selectedFunctionData?.condition,
|
||||
valueDescription: selectedFunctionData?.valueDescription,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user