mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-27 23:34:54 +00:00
adding the delay
This commit is contained in:
@ -2,9 +2,11 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
|
||||
|
||||
import 'package:syncrow_app/features/scene/model/create_scene_model.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';
|
||||
import 'package:syncrow_app/features/scene/widgets/alert_dialogs/alert_dialog_functions_body.dart';
|
||||
import 'package:syncrow_app/features/scene/widgets/alert_dialogs/alert_dialog_temperature_body.dart';
|
||||
@ -26,8 +28,9 @@ mixin SceneLogicHelper {
|
||||
}) {
|
||||
if (isOnlyDelayOrDelayLast(tasks)) {
|
||||
// Show snackbar indicating restriction
|
||||
Navigator.pop(context);
|
||||
context.showCustomSnackbar(
|
||||
message: 'Only a single delay or delay-last operations are allowed.',
|
||||
message: 'A single delay or delay-last operations are NOT allowed.',
|
||||
icon: const Icon(
|
||||
Icons.error,
|
||||
color: Colors.red,
|
||||
|
||||
@ -68,27 +68,26 @@ class Action {
|
||||
}
|
||||
|
||||
class ExecutorProperty {
|
||||
final String functionCode;
|
||||
final String? functionCode;
|
||||
final dynamic functionValue;
|
||||
final dynamic delaySeconds;
|
||||
|
||||
ExecutorProperty({
|
||||
required this.functionCode,
|
||||
required this.functionValue,
|
||||
this.functionCode,
|
||||
this.functionValue,
|
||||
this.delaySeconds,
|
||||
});
|
||||
|
||||
factory ExecutorProperty.fromRawJson(String str) =>
|
||||
ExecutorProperty.fromJson(json.decode(str));
|
||||
|
||||
String toRawJson() => json.encode(toJson());
|
||||
|
||||
factory ExecutorProperty.fromJson(Map<String, dynamic> json) =>
|
||||
ExecutorProperty(
|
||||
functionCode: json["functionCode"],
|
||||
functionCode: json["functionCode"] ?? '',
|
||||
functionValue: json["functionValue"],
|
||||
delaySeconds: json["delaySeconds"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"functionCode": functionCode,
|
||||
"functionValue": functionValue,
|
||||
"delaySeconds": delaySeconds,
|
||||
};
|
||||
}
|
||||
|
||||
@ -13,7 +13,6 @@ import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart';
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
import 'package:syncrow_app/navigation/routing_constants.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/strings_manager.dart';
|
||||
|
||||
@ -1,4 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.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';
|
||||
import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/light_divider.dart';
|
||||
|
||||
@ -74,10 +79,74 @@ class CustomBottomSheetWidget extends StatelessWidget {
|
||||
size: 16,
|
||||
color: ColorsManager.greyColor,
|
||||
),
|
||||
onPressed: () {},
|
||||
onPressed: () => _onDelayActionPressed(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onDelayActionPressed(BuildContext context) {
|
||||
final functionValues =
|
||||
context.read<CreateSceneBloc>().selectedValues['delay'];
|
||||
final functions = [
|
||||
SceneStaticFunction(
|
||||
deviceId: 'delay',
|
||||
deviceName: 'Delay The Action',
|
||||
icon: '',
|
||||
operationName: 'Delay The Action',
|
||||
code: 'delay',
|
||||
functionValue: 0,
|
||||
operationalValues: [
|
||||
SceneOperationalValue(icon: '', value: 0),
|
||||
],
|
||||
),
|
||||
];
|
||||
context.customAlertDialog(
|
||||
alertBody: AlertDialogCountdown(
|
||||
durationValue: functions[0].operationalValues.first.value,
|
||||
function: functions[0],
|
||||
functionValue: functionValues,
|
||||
),
|
||||
title: functions[0].operationName,
|
||||
onConfirm: () {
|
||||
final selectedValue =
|
||||
context.read<CreateSceneBloc>().selectedValues[functions[0].code];
|
||||
context.read<CreateSceneBloc>().add(TempHoldSceneTasksEvent(
|
||||
deviceControlModel: DeviceControlModel(
|
||||
deviceId: 'delay',
|
||||
code: functions[0].code,
|
||||
value: selectedValue,
|
||||
),
|
||||
deviceId: 'delay',
|
||||
operation: functions[0].operationName,
|
||||
icon: Assets.delay,
|
||||
deviceName: 'Delay The Action',
|
||||
uniqueId: functions[0].uniqueCustomId,
|
||||
));
|
||||
context
|
||||
.read<CreateSceneBloc>()
|
||||
.add(const AddTaskEvent(updateTaskListFromTemp: true));
|
||||
Navigator.pop(context);
|
||||
},
|
||||
onDismiss: () {
|
||||
final tempTaskList = context.read<CreateSceneBloc>().tempTasksList;
|
||||
if (tempTaskList.isEmpty) {
|
||||
context.read<CreateSceneBloc>().add(const ClearTempTaskListEvent());
|
||||
} else {
|
||||
for (var element in tempTaskList) {
|
||||
if (element.code == functions[0].code) {
|
||||
context
|
||||
.read<CreateSceneBloc>()
|
||||
.add(RemoveTempTaskByIdEvent(code: functions[0].code));
|
||||
context
|
||||
.read<CreateSceneBloc>()
|
||||
.add(RemoveFromSelectedValueById(code: functions[0].code));
|
||||
}
|
||||
}
|
||||
}
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,6 +43,9 @@ class _CreateSceneSaveButtonState extends State<CreateSceneSaveButton>
|
||||
listener: (context, state) {
|
||||
if (state is CreateSceneWithTasks) {
|
||||
if (state.success == true) {
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(context);
|
||||
|
||||
context.showCustomSnackbar(
|
||||
message: 'Scene created successfully',
|
||||
icon: const Icon(
|
||||
|
||||
Reference in New Issue
Block a user