mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 17:47:28 +00:00
push door lock automation functions
This commit is contained in:
@ -3,6 +3,8 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
|
||||
import 'package:syncrow_app/features/scene/enum/operation_dialog_type.dart';
|
||||
import 'package:syncrow_app/features/scene/helper/scene_logic_helper.dart';
|
||||
import 'package:syncrow_app/features/scene/helper/scene_operations_data_helper.dart';
|
||||
import 'package:syncrow_app/features/scene/model/scene_static_function.dart';
|
||||
import 'package:syncrow_app/features/scene/widgets/alert_dialogs/alert_dialog_countdown.dart';
|
||||
@ -19,7 +21,7 @@ import 'package:syncrow_app/utils/context_extension.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class DeviceFunctionsView extends StatelessWidget
|
||||
with SceneOperationsDataHelper {
|
||||
with SceneOperationsDataHelper, SceneLogicHelper {
|
||||
const DeviceFunctionsView({super.key});
|
||||
|
||||
@override
|
||||
@ -88,136 +90,130 @@ class DeviceFunctionsView extends StatelessWidget
|
||||
),
|
||||
leadingWidth: 80,
|
||||
padding: EdgeInsets.zero,
|
||||
child: Padding(
|
||||
child: ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: functions.length,
|
||||
padding: const EdgeInsets.only(top: 24.0),
|
||||
child: ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: functions.length,
|
||||
padding: EdgeInsets.zero,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemBuilder: (context, index) {
|
||||
return DefaultContainer(
|
||||
padding: index == 0
|
||||
? const EdgeInsets.only(top: 8)
|
||||
: index == functions.length - 1
|
||||
? const EdgeInsets.only(bottom: 8)
|
||||
: EdgeInsets.zero,
|
||||
margin: EdgeInsets.zero,
|
||||
borderRadius: index == 0
|
||||
? const BorderRadius.only(
|
||||
topLeft: Radius.circular(20),
|
||||
topRight: Radius.circular(20))
|
||||
: index == functions.length - 1
|
||||
? const BorderRadius.only(
|
||||
bottomLeft: Radius.circular(20),
|
||||
bottomRight: Radius.circular(20))
|
||||
: BorderRadius.zero,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
||||
builder: (context, state) {
|
||||
return SceneListTile(
|
||||
iconsSize: 22,
|
||||
minLeadingWidth: 20,
|
||||
assetPath: functions[index].icon,
|
||||
titleString: functions[index].operationName,
|
||||
trailingWidget: const Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
/// selected value or the default value
|
||||
// BodyMedium(text: ),
|
||||
Icon(
|
||||
Icons.arrow_forward_ios_rounded,
|
||||
color: ColorsManager.greyColor,
|
||||
size: 16,
|
||||
),
|
||||
],
|
||||
),
|
||||
onPressed: () {
|
||||
final functionValues = context
|
||||
.read<CreateSceneBloc>()
|
||||
.selectedValues[functions[index].code];
|
||||
itemBuilder: (context, index) {
|
||||
return DefaultContainer(
|
||||
padding: index == 0
|
||||
? const EdgeInsets.only(top: 8)
|
||||
: index == functions.length - 1
|
||||
? const EdgeInsets.only(bottom: 8)
|
||||
: EdgeInsets.zero,
|
||||
margin: EdgeInsets.zero,
|
||||
borderRadius: index == 0
|
||||
? const BorderRadius.only(
|
||||
topLeft: Radius.circular(20),
|
||||
topRight: Radius.circular(20))
|
||||
: index == functions.length - 1
|
||||
? const BorderRadius.only(
|
||||
bottomLeft: Radius.circular(20),
|
||||
bottomRight: Radius.circular(20))
|
||||
: BorderRadius.zero,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
||||
builder: (context, state) {
|
||||
return SceneListTile(
|
||||
iconsSize: 22,
|
||||
minLeadingWidth: 20,
|
||||
assetPath: functions[index].icon,
|
||||
titleString: functions[index].operationName,
|
||||
trailingWidget: const Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
/// selected value or the default value
|
||||
// BodyMedium(text: ),
|
||||
Icon(
|
||||
Icons.arrow_forward_ios_rounded,
|
||||
color: ColorsManager.greyColor,
|
||||
size: 16,
|
||||
),
|
||||
],
|
||||
),
|
||||
onPressed: () {
|
||||
final functionValues = context
|
||||
.read<CreateSceneBloc>()
|
||||
.selectedValues[functions[index].code];
|
||||
|
||||
context.customAlertDialog(
|
||||
alertBody: functions[index].code == 'temp_set'
|
||||
? AlertDialogTemperatureBody(
|
||||
taskItem: functions[index],
|
||||
functionValue: functionValues,
|
||||
)
|
||||
: (functions[index]
|
||||
.code
|
||||
.contains('countdown') ||
|
||||
functions[index]
|
||||
.code
|
||||
.contains('presence_time'))
|
||||
? AlertDialogCountdown(
|
||||
durationValue: functions[index]
|
||||
.operationalValues
|
||||
.first
|
||||
.value,
|
||||
function: functions[index],
|
||||
functionValue: functionValues,
|
||||
)
|
||||
: AlertDialogFunctionsOperationsBody(
|
||||
taskItem: functions[index],
|
||||
functionValue: functionValues,
|
||||
),
|
||||
title: functions[index].operationName,
|
||||
onConfirm: () {
|
||||
final selectedValue = context
|
||||
.read<CreateSceneBloc>()
|
||||
.selectedValues[functions[index].code];
|
||||
if (selectedValue == null) {
|
||||
return;
|
||||
}
|
||||
context
|
||||
.read<CreateSceneBloc>()
|
||||
.add(TempHoldSceneTasksEvent(
|
||||
deviceControlModel: DeviceControlModel(
|
||||
deviceId: device.uuid,
|
||||
code: functions[index].code,
|
||||
value: selectedValue,
|
||||
context.customAlertDialog(
|
||||
alertBody: functions[index].operationDialogType ==
|
||||
OperationDialogType.temperature
|
||||
? AlertDialogTemperatureBody(
|
||||
taskItem: functions[index],
|
||||
functionValue: functionValues,
|
||||
)
|
||||
: ((functions[index].operationDialogType ==
|
||||
OperationDialogType.countdown) ||
|
||||
(functions[index].operationDialogType ==
|
||||
OperationDialogType.countdown))
|
||||
? AlertDialogCountdown(
|
||||
durationValue: functions[index]
|
||||
.operationalValues
|
||||
.first
|
||||
.value,
|
||||
function: functions[index],
|
||||
functionValue: functionValues,
|
||||
)
|
||||
: AlertDialogFunctionsOperationsBody(
|
||||
taskItem: functions[index],
|
||||
functionValue: functionValues,
|
||||
),
|
||||
deviceId: device.uuid ?? '',
|
||||
operation: functions[index].operationName,
|
||||
icon: device.icon ?? '',
|
||||
deviceName: device.name ?? '',
|
||||
uniqueId: functions[index].uniqueCustomId,
|
||||
));
|
||||
Navigator.pop(context);
|
||||
},
|
||||
onDismiss: () {
|
||||
final tempTaskList = context
|
||||
.read<CreateSceneBloc>()
|
||||
.tempTasksList;
|
||||
for (var element in tempTaskList) {
|
||||
if (element.code == functions[index].code) {
|
||||
context.read<CreateSceneBloc>().add(
|
||||
RemoveTempTaskByIdEvent(
|
||||
code: functions[index].code));
|
||||
context.read<CreateSceneBloc>().add(
|
||||
RemoveFromSelectedValueById(
|
||||
code: functions[index].code));
|
||||
}
|
||||
title: functions[index].operationName,
|
||||
onConfirm: () {
|
||||
final selectedValue = context
|
||||
.read<CreateSceneBloc>()
|
||||
.selectedValues[functions[index].code];
|
||||
if (selectedValue == null) {
|
||||
return;
|
||||
}
|
||||
context
|
||||
.read<CreateSceneBloc>()
|
||||
.add(TempHoldSceneTasksEvent(
|
||||
deviceControlModel: DeviceControlModel(
|
||||
deviceId: device.uuid,
|
||||
code: functions[index].code,
|
||||
value: selectedValue,
|
||||
),
|
||||
deviceId: device.uuid ?? '',
|
||||
operation: functions[index].operationName,
|
||||
icon: device.icon ?? '',
|
||||
deviceName: device.name ?? '',
|
||||
uniqueId: functions[index].uniqueCustomId,
|
||||
));
|
||||
Navigator.pop(context);
|
||||
},
|
||||
onDismiss: () {
|
||||
final tempTaskList =
|
||||
context.read<CreateSceneBloc>().tempTasksList;
|
||||
for (var element in tempTaskList) {
|
||||
if (element.code == functions[index].code) {
|
||||
context.read<CreateSceneBloc>().add(
|
||||
RemoveTempTaskByIdEvent(
|
||||
code: functions[index].code));
|
||||
context.read<CreateSceneBloc>().add(
|
||||
RemoveFromSelectedValueById(
|
||||
code: functions[index].code));
|
||||
}
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
index != functions.length - 1
|
||||
? SizedBox(
|
||||
width: context.width * 0.8,
|
||||
child: const LightDivider())
|
||||
: const SizedBox(),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
}
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
index != functions.length - 1
|
||||
? SizedBox(
|
||||
width: context.width * 0.8,
|
||||
child: const LightDivider())
|
||||
: const SizedBox(),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user