mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-15 09:45:25 +00:00
show curtain in devices and implement dialog for if and then (#263)
last integrate with backend <!-- Thanks for contributing! Provide a description of your changes below and a general summary in the title Please look at the following checklist to ensure that your PR can be accepted quickly: --> ## Jira Ticket [SP-1728](https://syncrow.atlassian.net/browse/SP-1728) ## Description implement the dialog for CURTAIN and make it appears with devices in making Routine integrate it with backend and test it ## Type of Change <!--- Put an `x` in all the boxes that apply: --> - [x] ✨ New feature (non-breaking change which adds functionality) - [ ] 🛠️ Bug fix (non-breaking change which fixes an issue) - [ ] ❌ Breaking change (fix or feature that would cause existing functionality to change) - [ ] 🧹 Code refactor - [ ] ✅ Build configuration change - [ ] 📝 Documentation - [ ] 🗑️ Chore [SP-1728]: https://syncrow.atlassian.net/browse/SP-1728?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
This commit is contained in:
@ -6,6 +6,7 @@ import 'package:syncrow_web/pages/device_managment/all_devices/models/device_tag
|
|||||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/room.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/room.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/unit.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/unit.dart';
|
||||||
import 'package:syncrow_web/pages/routines/models/ac/ac_function.dart';
|
import 'package:syncrow_web/pages/routines/models/ac/ac_function.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/models/curtain/curtain_function.dart';
|
||||||
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
|
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
|
||||||
import 'package:syncrow_web/pages/routines/models/flush/flush_functions.dart';
|
import 'package:syncrow_web/pages/routines/models/flush/flush_functions.dart';
|
||||||
import 'package:syncrow_web/pages/routines/models/gang_switches/one_gang_switch/one_gang_switch.dart';
|
import 'package:syncrow_web/pages/routines/models/gang_switches/one_gang_switch/one_gang_switch.dart';
|
||||||
@ -359,6 +360,14 @@ SOS
|
|||||||
uuid: uuid ?? '',
|
uuid: uuid ?? '',
|
||||||
name: name ?? '',
|
name: name ?? '',
|
||||||
);
|
);
|
||||||
|
case 'CUR':
|
||||||
|
return [
|
||||||
|
ControlCurtainFunction(
|
||||||
|
deviceId: uuid ?? '',
|
||||||
|
deviceName: name ?? '',
|
||||||
|
type: 'BOTH',
|
||||||
|
)
|
||||||
|
];
|
||||||
case 'NCPS':
|
case 'NCPS':
|
||||||
return [
|
return [
|
||||||
FlushPresenceDelayFunction(
|
FlushPresenceDelayFunction(
|
||||||
@ -441,15 +450,10 @@ SOS
|
|||||||
VoltageCStatusFunction(
|
VoltageCStatusFunction(
|
||||||
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
|
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
|
||||||
CurrentCStatusFunction(
|
CurrentCStatusFunction(
|
||||||
deviceId: uuid ?? '',
|
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
|
||||||
deviceName: name ?? '',
|
|
||||||
type: 'IF'),
|
|
||||||
PowerFactorCStatusFunction(
|
PowerFactorCStatusFunction(
|
||||||
deviceId: uuid ?? '',
|
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
|
||||||
deviceName: name ?? '',
|
|
||||||
type: 'IF'),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
|||||||
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
|
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
|
||||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/ac_dialog.dart';
|
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/ac_dialog.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/ceiling_sensor_helper.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/curtain_dialog.dart';
|
||||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/flush_presence_sensor/flush_presence_sensor.dart';
|
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/flush_presence_sensor/flush_presence_sensor.dart';
|
||||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/gateway/gateway_helper.dart';
|
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/gateway/gateway_helper.dart';
|
||||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/one_gang_switch_dialog.dart';
|
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/one_gang_switch_dialog.dart';
|
||||||
@ -26,7 +27,7 @@ class DeviceDialogHelper {
|
|||||||
final result = await _getDialogForDeviceType(
|
final result = await _getDialogForDeviceType(
|
||||||
dialogType: dialogType,
|
dialogType: dialogType,
|
||||||
context: context,
|
context: context,
|
||||||
productType: data['productType'],
|
productType: data['productType'] as String,
|
||||||
data: data,
|
data: data,
|
||||||
functions: functions,
|
functions: functions,
|
||||||
removeComparetors: removeComparetors,
|
removeComparetors: removeComparetors,
|
||||||
@ -65,7 +66,14 @@ class DeviceDialogHelper {
|
|||||||
removeComparetors: removeComparetors,
|
removeComparetors: removeComparetors,
|
||||||
dialogType: dialogType,
|
dialogType: dialogType,
|
||||||
);
|
);
|
||||||
|
case 'CUR':
|
||||||
|
return CurtainHelper.showControlDialog(
|
||||||
|
dialogType: dialogType,
|
||||||
|
context: context,
|
||||||
|
functions: functions,
|
||||||
|
uniqueCustomId: data['uniqueCustomId'],
|
||||||
|
device: data['device'],
|
||||||
|
);
|
||||||
case '1G':
|
case '1G':
|
||||||
return OneGangSwitchHelper.showSwitchFunctionsDialog(
|
return OneGangSwitchHelper.showSwitchFunctionsDialog(
|
||||||
dialogType: dialogType,
|
dialogType: dialogType,
|
||||||
|
49
lib/pages/routines/models/curtain/curtain_function.dart
Normal file
49
lib/pages/routines/models/curtain/curtain_function.dart
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import 'package:syncrow_web/pages/device_managment/curtain/model/curtain_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/models/curtain/curtain_opertion_value.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/models/device_functions.dart'
|
||||||
|
show DeviceFunction;
|
||||||
|
import 'package:syncrow_web/utils/constants/app_enum.dart';
|
||||||
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
|
|
||||||
|
abstract class CurtainFunction extends DeviceFunction<CurtainModel> {
|
||||||
|
final String type;
|
||||||
|
CurtainFunction({
|
||||||
|
required super.deviceId,
|
||||||
|
required super.deviceName,
|
||||||
|
required this.type,
|
||||||
|
required super.code,
|
||||||
|
required super.operationName,
|
||||||
|
required super.icon,
|
||||||
|
});
|
||||||
|
List<CurtainOperationalValue> getOperationalValues();
|
||||||
|
}
|
||||||
|
|
||||||
|
class ControlCurtainFunction extends CurtainFunction {
|
||||||
|
ControlCurtainFunction({
|
||||||
|
required super.deviceId,
|
||||||
|
required super.deviceName,
|
||||||
|
required super.type,
|
||||||
|
super.code = 'control',
|
||||||
|
super.operationName = 'Control',
|
||||||
|
super.icon = Assets.curtain,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<CurtainOperationalValue> getOperationalValues() => [
|
||||||
|
CurtainOperationalValue(
|
||||||
|
icon: Assets.curtain,
|
||||||
|
description: 'OPEN',
|
||||||
|
value: 'open',
|
||||||
|
),
|
||||||
|
CurtainOperationalValue(
|
||||||
|
icon: Assets.curtain,
|
||||||
|
description: 'STOP',
|
||||||
|
value: 'stop',
|
||||||
|
),
|
||||||
|
CurtainOperationalValue(
|
||||||
|
icon: Assets.curtain,
|
||||||
|
description: 'CLOSE',
|
||||||
|
value: 'close',
|
||||||
|
)
|
||||||
|
];
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
class CurtainOperationalValue {
|
||||||
|
final String icon;
|
||||||
|
final String description;
|
||||||
|
final String value;
|
||||||
|
|
||||||
|
CurtainOperationalValue({
|
||||||
|
required this.icon,
|
||||||
|
required this.description,
|
||||||
|
required this.value,
|
||||||
|
});
|
||||||
|
}
|
@ -148,6 +148,7 @@ class IfContainer extends StatelessWidget {
|
|||||||
'NCPS',
|
'NCPS',
|
||||||
'WH',
|
'WH',
|
||||||
'PC',
|
'PC',
|
||||||
|
'CUR',
|
||||||
].contains(mutableData['productType'])) {
|
].contains(mutableData['productType'])) {
|
||||||
context
|
context
|
||||||
.read<RoutineBloc>()
|
.read<RoutineBloc>()
|
||||||
|
@ -28,6 +28,7 @@ class _RoutineDevicesState extends State<RoutineDevices> {
|
|||||||
'NCPS',
|
'NCPS',
|
||||||
'WH',
|
'WH',
|
||||||
'PC',
|
'PC',
|
||||||
|
'CUR',
|
||||||
};
|
};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
270
lib/pages/routines/widgets/routine_dialogs/curtain_dialog.dart
Normal file
270
lib/pages/routines/widgets/routine_dialogs/curtain_dialog.dart
Normal file
@ -0,0 +1,270 @@
|
|||||||
|
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/curtain/curtain_function.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/models/curtain/curtain_opertion_value.dart';
|
||||||
|
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/helpers/routine_tap_function_helper.dart';
|
||||||
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
|
|
||||||
|
class CurtainHelper {
|
||||||
|
static Future<Map<String, dynamic>?> showControlDialog({
|
||||||
|
required String dialogType,
|
||||||
|
required BuildContext context,
|
||||||
|
required List<DeviceFunction> functions,
|
||||||
|
required String uniqueCustomId,
|
||||||
|
required AllDevicesModel? device,
|
||||||
|
}) async {
|
||||||
|
List<ControlCurtainFunction> curtainFunctions =
|
||||||
|
functions.whereType<ControlCurtainFunction>().where((function) {
|
||||||
|
if (dialogType == 'THEN') {
|
||||||
|
return function.type == 'THEN' || function.type == 'BOTH';
|
||||||
|
}
|
||||||
|
return function.type == 'IF' || function.type == 'BOTH';
|
||||||
|
}).toList();
|
||||||
|
return showDialog<Map<String, dynamic>?>(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => BlocProvider(
|
||||||
|
create: (_) => FunctionBloc()..add(const InitializeFunctions([])),
|
||||||
|
child: AlertDialog(
|
||||||
|
contentPadding: EdgeInsets.zero,
|
||||||
|
content: BlocBuilder<FunctionBloc, FunctionBlocState>(
|
||||||
|
builder: (context, 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 Container(
|
||||||
|
width: selectedFunction != null ? 600 : 360,
|
||||||
|
height: 450,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
),
|
||||||
|
padding: const EdgeInsets.only(top: 20),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
const DialogHeader('AC Functions'),
|
||||||
|
Expanded(
|
||||||
|
child: Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
// Function list
|
||||||
|
SizedBox(
|
||||||
|
width: selectedFunction != null ? 320 : 360,
|
||||||
|
child: _buildFunctionsList(
|
||||||
|
context: context,
|
||||||
|
curtainFunctions: curtainFunctions,
|
||||||
|
onFunctionSelected:
|
||||||
|
(functionCode, operationName) {
|
||||||
|
RoutineTapFunctionHelper.onTapFunction(
|
||||||
|
context,
|
||||||
|
functionCode: functionCode,
|
||||||
|
functionOperationName: operationName,
|
||||||
|
functionValueDescription:
|
||||||
|
selectedFunctionData.valueDescription,
|
||||||
|
deviceUuid: device?.uuid,
|
||||||
|
codesToAddIntoFunctionsWithDefaultValue: [
|
||||||
|
'temp_set',
|
||||||
|
'temp_current',
|
||||||
|
],
|
||||||
|
defaultValue: 0);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
// Value selector
|
||||||
|
if (selectedFunction != null)
|
||||||
|
Expanded(
|
||||||
|
child: _buildValueSelector(
|
||||||
|
context: context,
|
||||||
|
selectedFunction: selectedFunction,
|
||||||
|
selectedFunctionData: selectedFunctionData,
|
||||||
|
controlFunctions: curtainFunctions,
|
||||||
|
device: device,
|
||||||
|
operationName: selectedOperationName ?? '',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
DialogFooter(
|
||||||
|
onCancel: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
onConfirm: state.addedFunctions.isNotEmpty
|
||||||
|
? () {
|
||||||
|
/// add the functions to the routine bloc
|
||||||
|
context.read<RoutineBloc>().add(
|
||||||
|
AddFunctionToRoutine(
|
||||||
|
state.addedFunctions,
|
||||||
|
uniqueCustomId,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Return the device data to be added to the container
|
||||||
|
Navigator.pop(context, {
|
||||||
|
'deviceId': functions.first.deviceId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
isConfirmEnabled: selectedFunction != null,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
).then((value) {
|
||||||
|
return value;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static Widget _buildFunctionsList({
|
||||||
|
required BuildContext context,
|
||||||
|
required List<ControlCurtainFunction> curtainFunctions,
|
||||||
|
required Function(String, String) onFunctionSelected,
|
||||||
|
}) {
|
||||||
|
return ListView.separated(
|
||||||
|
shrinkWrap: false,
|
||||||
|
physics: const AlwaysScrollableScrollPhysics(),
|
||||||
|
itemCount: curtainFunctions.length,
|
||||||
|
separatorBuilder: (context, index) => const Padding(
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 40.0),
|
||||||
|
child: Divider(
|
||||||
|
color: ColorsManager.dividerColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final function = curtainFunctions[index];
|
||||||
|
return ListTile(
|
||||||
|
leading: SvgPicture.asset(
|
||||||
|
function.icon,
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
placeholderBuilder: (BuildContext context) => Container(
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
color: Colors.transparent,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
title: Text(
|
||||||
|
function.operationName,
|
||||||
|
style: context.textTheme.bodyMedium,
|
||||||
|
),
|
||||||
|
trailing: const Icon(
|
||||||
|
Icons.arrow_forward_ios,
|
||||||
|
size: 16,
|
||||||
|
color: ColorsManager.textGray,
|
||||||
|
),
|
||||||
|
onTap: () => onFunctionSelected(
|
||||||
|
function.code,
|
||||||
|
function.operationName,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Widget _buildValueSelector({
|
||||||
|
required BuildContext context,
|
||||||
|
required String selectedFunction,
|
||||||
|
required DeviceFunctionData? selectedFunctionData,
|
||||||
|
required List<ControlCurtainFunction> controlFunctions,
|
||||||
|
AllDevicesModel? device,
|
||||||
|
required String operationName,
|
||||||
|
}) {
|
||||||
|
final selectedFn =
|
||||||
|
controlFunctions.firstWhere((f) => f.code == selectedFunction);
|
||||||
|
|
||||||
|
// Rest of your existing code for other value selectors
|
||||||
|
final values = selectedFn.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<CurtainOperationalValue> values,
|
||||||
|
required dynamic selectedValue,
|
||||||
|
AllDevicesModel? device,
|
||||||
|
required String operationName,
|
||||||
|
required String selectCode,
|
||||||
|
DeviceFunctionData? selectedFunctionData,
|
||||||
|
|
||||||
|
// required Function(dynamic) onValueChanged,
|
||||||
|
}) {
|
||||||
|
return ListView.builder(
|
||||||
|
shrinkWrap: false,
|
||||||
|
physics: const AlwaysScrollableScrollPhysics(),
|
||||||
|
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: (BuildContext 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,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -30,123 +30,121 @@ class ThenContainer extends StatelessWidget {
|
|||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 18, fontWeight: FontWeight.bold)),
|
fontSize: 18, fontWeight: FontWeight.bold)),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
state.isLoading && state.isUpdate == true
|
if (state.isLoading && state.isUpdate == true)
|
||||||
? const Center(
|
const Center(
|
||||||
child: CircularProgressIndicator(),
|
child: CircularProgressIndicator(),
|
||||||
)
|
)
|
||||||
: Wrap(
|
else
|
||||||
spacing: 8,
|
Wrap(
|
||||||
runSpacing: 8,
|
spacing: 8,
|
||||||
children: List.generate(
|
runSpacing: 8,
|
||||||
state.thenItems.length,
|
children: List.generate(
|
||||||
(index) => GestureDetector(
|
state.thenItems.length,
|
||||||
onTap: () async {
|
(index) => GestureDetector(
|
||||||
if (state.thenItems[index]
|
onTap: () async {
|
||||||
['deviceId'] ==
|
if (state.thenItems[index]['deviceId'] ==
|
||||||
'delay') {
|
'delay') {
|
||||||
final result = await DelayHelper
|
final result = await DelayHelper
|
||||||
.showDelayPickerDialog(context,
|
.showDelayPickerDialog(context,
|
||||||
state.thenItems[index]);
|
state.thenItems[index]);
|
||||||
|
|
||||||
if (result != null) {
|
|
||||||
context
|
|
||||||
.read<RoutineBloc>()
|
|
||||||
.add(AddToThenContainer({
|
|
||||||
...state.thenItems[index],
|
|
||||||
'imagePath': Assets.delay,
|
|
||||||
'title': 'Delay',
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state.thenItems[index]['type'] ==
|
|
||||||
'automation') {
|
|
||||||
final result = await showDialog<bool>(
|
|
||||||
context: context,
|
|
||||||
builder: (BuildContext context) =>
|
|
||||||
AutomationDialog(
|
|
||||||
automationName:
|
|
||||||
state.thenItems[index]
|
|
||||||
['name'] ??
|
|
||||||
'Automation',
|
|
||||||
automationId:
|
|
||||||
state.thenItems[index]
|
|
||||||
['deviceId'] ??
|
|
||||||
'',
|
|
||||||
uniqueCustomId:
|
|
||||||
state.thenItems[index]
|
|
||||||
['uniqueCustomId'],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (result != null) {
|
|
||||||
context
|
|
||||||
.read<RoutineBloc>()
|
|
||||||
.add(AddToThenContainer({
|
|
||||||
...state.thenItems[index],
|
|
||||||
'imagePath':
|
|
||||||
Assets.automation,
|
|
||||||
'title':
|
|
||||||
state.thenItems[index]
|
|
||||||
['name'] ??
|
|
||||||
state.thenItems[index]
|
|
||||||
['title'],
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final result = await DeviceDialogHelper
|
|
||||||
.showDeviceDialog(
|
|
||||||
context: context,
|
|
||||||
data: state.thenItems[index],
|
|
||||||
removeComparetors: true,
|
|
||||||
dialogType: "THEN");
|
|
||||||
|
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
context.read<RoutineBloc>().add(
|
context
|
||||||
AddToThenContainer(
|
.read<RoutineBloc>()
|
||||||
state.thenItems[index]));
|
.add(AddToThenContainer({
|
||||||
} else if (![
|
...state.thenItems[index],
|
||||||
'AC',
|
'imagePath': Assets.delay,
|
||||||
'1G',
|
'title': 'Delay',
|
||||||
'2G',
|
}));
|
||||||
'3G',
|
|
||||||
'WPS',
|
|
||||||
'CPS',
|
|
||||||
"GW",
|
|
||||||
"NCPS",
|
|
||||||
'WH',
|
|
||||||
].contains(state.thenItems[index]
|
|
||||||
['productType'])) {
|
|
||||||
context.read<RoutineBloc>().add(
|
|
||||||
AddToThenContainer(
|
|
||||||
state.thenItems[index]));
|
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.thenItems[index]['type'] ==
|
||||||
|
'automation') {
|
||||||
|
final result = await showDialog<bool>(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) =>
|
||||||
|
AutomationDialog(
|
||||||
|
automationName:
|
||||||
|
state.thenItems[index]['name']
|
||||||
|
as String? ??
|
||||||
|
'Automation',
|
||||||
|
automationId: state.thenItems[index]
|
||||||
|
['deviceId'] as String? ??
|
||||||
|
'',
|
||||||
|
uniqueCustomId: state
|
||||||
|
.thenItems[index]
|
||||||
|
['uniqueCustomId'] as String,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result != null) {
|
||||||
|
context
|
||||||
|
.read<RoutineBloc>()
|
||||||
|
.add(AddToThenContainer({
|
||||||
|
...state.thenItems[index],
|
||||||
|
'imagePath': Assets.automation,
|
||||||
|
'title': state.thenItems[index]
|
||||||
|
['name'] ??
|
||||||
|
state.thenItems[index]
|
||||||
|
['title'],
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final result = await DeviceDialogHelper
|
||||||
|
.showDeviceDialog(
|
||||||
|
context: context,
|
||||||
|
data: state.thenItems[index],
|
||||||
|
removeComparetors: true,
|
||||||
|
dialogType: 'THEN');
|
||||||
|
if (result != null) {
|
||||||
|
context.read<RoutineBloc>().add(
|
||||||
|
AddToThenContainer(
|
||||||
|
state.thenItems[index]));
|
||||||
|
} else if (![
|
||||||
|
'AC',
|
||||||
|
'1G',
|
||||||
|
'2G',
|
||||||
|
'3G',
|
||||||
|
'WPS',
|
||||||
|
'CPS',
|
||||||
|
'GW',
|
||||||
|
'NCPS',
|
||||||
|
'WH',
|
||||||
|
'CUR',
|
||||||
|
].contains(state.thenItems[index]
|
||||||
|
['productType'])) {
|
||||||
|
context.read<RoutineBloc>().add(
|
||||||
|
AddToThenContainer(
|
||||||
|
state.thenItems[index]));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: DraggableCard(
|
||||||
|
imagePath: state.thenItems[index]
|
||||||
|
['imagePath'] as String? ??
|
||||||
|
'',
|
||||||
|
title: state.thenItems[index]['title']
|
||||||
|
as String? ??
|
||||||
|
'',
|
||||||
|
deviceData: state.thenItems[index],
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 4, vertical: 8),
|
||||||
|
isFromThen: true,
|
||||||
|
isFromIf: false,
|
||||||
|
onRemove: () {
|
||||||
|
context.read<RoutineBloc>().add(
|
||||||
|
RemoveDragCard(
|
||||||
|
index: index,
|
||||||
|
isFromThen: true,
|
||||||
|
key: state.thenItems[index]
|
||||||
|
['uniqueCustomId']
|
||||||
|
as String));
|
||||||
},
|
},
|
||||||
child: DraggableCard(
|
),
|
||||||
imagePath: state.thenItems[index]
|
))),
|
||||||
['imagePath'] ??
|
|
||||||
'',
|
|
||||||
title: state.thenItems[index]
|
|
||||||
['title'] ??
|
|
||||||
'',
|
|
||||||
deviceData: state.thenItems[index],
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 4, vertical: 8),
|
|
||||||
isFromThen: true,
|
|
||||||
isFromIf: false,
|
|
||||||
onRemove: () {
|
|
||||||
context.read<RoutineBloc>().add(
|
|
||||||
RemoveDragCard(
|
|
||||||
index: index,
|
|
||||||
isFromThen: true,
|
|
||||||
key: state.thenItems[index]
|
|
||||||
['uniqueCustomId']));
|
|
||||||
},
|
|
||||||
),
|
|
||||||
))),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -230,7 +228,7 @@ class ThenContainer extends StatelessWidget {
|
|||||||
context: context,
|
context: context,
|
||||||
data: mutableData,
|
data: mutableData,
|
||||||
removeComparetors: true,
|
removeComparetors: true,
|
||||||
dialogType: "THEN");
|
dialogType: 'THEN');
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
context.read<RoutineBloc>().add(AddToThenContainer(mutableData));
|
context.read<RoutineBloc>().add(AddToThenContainer(mutableData));
|
||||||
} else if (![
|
} else if (![
|
||||||
@ -241,9 +239,10 @@ class ThenContainer extends StatelessWidget {
|
|||||||
'WPS',
|
'WPS',
|
||||||
'GW',
|
'GW',
|
||||||
'CPS',
|
'CPS',
|
||||||
"NCPS",
|
'NCPS',
|
||||||
"WH",
|
'WH',
|
||||||
'PC',
|
'PC',
|
||||||
|
'CUR',
|
||||||
].contains(mutableData['productType'])) {
|
].contains(mutableData['productType'])) {
|
||||||
context.read<RoutineBloc>().add(AddToThenContainer(mutableData));
|
context.read<RoutineBloc>().add(AddToThenContainer(mutableData));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user