mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-08-26 09:59:40 +00:00
fix bugs
This commit is contained in:
@ -2,8 +2,14 @@ import 'dart:async';
|
||||
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.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/enum/create_scene_enum.dart';
|
||||
import 'package:syncrow_app/features/scene/enum/operation_dialog_type.dart';
|
||||
import 'package:syncrow_app/features/scene/model/smart_scene_enable.dart';
|
||||
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
import 'package:syncrow_app/navigation/navigation_service.dart';
|
||||
part 'smart_scene_select_dart_event.dart';
|
||||
part 'smart_scene_select_dart_state.dart';
|
||||
|
||||
@ -19,7 +25,29 @@ class SmartSceneSelectBloc
|
||||
FutureOr<void> _onSmartSceneEnable(
|
||||
SmartSceneEnableEvent event, Emitter<SmartSceneSelectState> emit) {
|
||||
smartSceneEnable = event.smartSceneEnable;
|
||||
NavigationService.navigatorKey.currentState!.context
|
||||
.read<CreateSceneBloc>()
|
||||
.add(TempHoldSceneTasksEvent(
|
||||
deviceControlModel: DeviceControlModel(
|
||||
deviceId: smartSceneEnable?.entityId ?? '',
|
||||
code: CreateSceneEnum.smartSceneSelect.name,
|
||||
value: '',
|
||||
),
|
||||
deviceId: smartSceneEnable?.sceneORAutomationName ?? '',
|
||||
operation: smartSceneEnable?.actionExecutor ?? '',
|
||||
icon: smartSceneEnable?.isAutomation == true
|
||||
? Assets.player
|
||||
: Assets.handClickIcon,
|
||||
deviceName: smartSceneEnable?.sceneORAutomationName ?? '',
|
||||
uniqueId: '',
|
||||
operationType: OperationDialogType.none,
|
||||
isAutomation: false,
|
||||
));
|
||||
|
||||
emit(SmartSceneSelected(smartSceneEnable: smartSceneEnable!));
|
||||
NavigationService.navigatorKey.currentState!.context
|
||||
.read<CreateSceneBloc>()
|
||||
.add(const AddTaskEvent(isAutomation: false));
|
||||
}
|
||||
|
||||
FutureOr<void> _smartSceneClear(
|
||||
@ -27,4 +55,4 @@ class SmartSceneSelectBloc
|
||||
smartSceneEnable = null;
|
||||
emit(SmartSceneSelectInitial());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
enum CreateSceneEnum {
|
||||
tabToRun,
|
||||
deviceStatusChanges,
|
||||
smartSceneSelect,
|
||||
none,
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ 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/bloc/smart_scene/smart_scene_select_dart_bloc.dart';
|
||||
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
|
||||
import 'package:syncrow_app/features/scene/enum/operation_dialog_type.dart';
|
||||
import 'package:syncrow_app/features/scene/model/create_automation_model.dart';
|
||||
import 'package:syncrow_app/features/scene/model/create_scene_model.dart';
|
||||
@ -32,142 +33,129 @@ mixin SceneLogicHelper {
|
||||
final sceneBloc = context.read<CreateSceneBloc>();
|
||||
final smartSceneBloc = context.read<SmartSceneSelectBloc>();
|
||||
|
||||
if (isOnlyDelayOrDelayLast(actions)) {
|
||||
context.showCustomSnackbar(
|
||||
message: 'A single delay or delay-last operations are NOT allowed.',
|
||||
icon: const Icon(
|
||||
Icons.error,
|
||||
color: Colors.red,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isAutomation) {
|
||||
// Handle Automation Creation
|
||||
if (isOnlyDelayOrDelayLast(actions)) {
|
||||
Navigator.pop(context);
|
||||
context.showCustomSnackbar(
|
||||
message: 'A single delay or delay-last operations are NOT allowed.',
|
||||
icon: const Icon(
|
||||
Icons.error,
|
||||
color: Colors.red,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
final createAutomationModel = CreateAutomationModel(
|
||||
unitUuid: HomeCubit.getInstance().selectedSpace!.id ?? '',
|
||||
automationName: sceneName.text,
|
||||
decisionExpr: sceneBloc.conditionRule,
|
||||
effectiveTime: sceneBloc.effectiveTime ??
|
||||
EffectiveTime(start: '00:00', end: '23:59', loops: '1111111'),
|
||||
conditions: List.generate(
|
||||
conditions.length,
|
||||
final createAutomationModel = CreateAutomationModel(
|
||||
unitUuid: HomeCubit.getInstance().selectedSpace!.id ?? '',
|
||||
automationName: sceneName.text,
|
||||
decisionExpr: sceneBloc.conditionRule,
|
||||
effectiveTime: sceneBloc.effectiveTime ??
|
||||
EffectiveTime(start: '00:00', end: '23:59', loops: '1111111'),
|
||||
conditions: List.generate(
|
||||
conditions.length,
|
||||
(index) {
|
||||
final task = conditions[index];
|
||||
return CreateCondition(
|
||||
code: index + 1,
|
||||
entityId: task.deviceId,
|
||||
entityType: 'device_report',
|
||||
expr: ConditionExpr(
|
||||
statusCode: task.code,
|
||||
comparator: task.comparator ?? '==',
|
||||
statusValue: task.functionValue,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
actions: [
|
||||
...List.generate(
|
||||
actions.length,
|
||||
(index) {
|
||||
final task = conditions[index];
|
||||
return CreateCondition(
|
||||
code: index + 1,
|
||||
final task = actions[index];
|
||||
if (task.deviceId == 'delay') {
|
||||
return CreateSceneAction(
|
||||
entityId: actions[index].deviceId,
|
||||
actionExecutor: 'delay',
|
||||
executorProperty: CreateSceneExecutorProperty(
|
||||
functionCode: '',
|
||||
functionValue: '',
|
||||
delaySeconds: task.functionValue,
|
||||
),
|
||||
);
|
||||
}
|
||||
if (task.code == CreateSceneEnum.smartSceneSelect.name) {
|
||||
return CreateSceneAction(
|
||||
entityId: smartSceneBloc.smartSceneEnable?.entityId ?? '',
|
||||
actionExecutor:
|
||||
smartSceneBloc.smartSceneEnable?.actionExecutor ?? '',
|
||||
executorProperty: null);
|
||||
}
|
||||
return CreateSceneAction(
|
||||
entityId: task.deviceId,
|
||||
entityType: 'device_report',
|
||||
expr: ConditionExpr(
|
||||
statusCode: task.code,
|
||||
comparator: task.comparator ?? '==',
|
||||
statusValue: task.functionValue,
|
||||
actionExecutor: 'device_issue',
|
||||
executorProperty: CreateSceneExecutorProperty(
|
||||
functionCode: task.code,
|
||||
functionValue: task.functionValue,
|
||||
delaySeconds: 0,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
actions: [
|
||||
...List.generate(
|
||||
actions.length,
|
||||
(index) {
|
||||
final task = actions[index];
|
||||
if (task.deviceId == 'delay') {
|
||||
return CreateSceneAction(
|
||||
entityId: actions[index].deviceId,
|
||||
actionExecutor: 'delay',
|
||||
executorProperty: CreateSceneExecutorProperty(
|
||||
functionCode: '',
|
||||
functionValue: '',
|
||||
delaySeconds: task.functionValue,
|
||||
),
|
||||
);
|
||||
}
|
||||
return CreateSceneAction(
|
||||
entityId: task.deviceId,
|
||||
actionExecutor: 'device_issue',
|
||||
executorProperty: CreateSceneExecutorProperty(
|
||||
functionCode: task.code,
|
||||
functionValue: task.functionValue,
|
||||
delaySeconds: 0,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
if (smartSceneBloc.smartSceneEnable != null)
|
||||
CreateSceneAction(
|
||||
entityId: smartSceneBloc.smartSceneEnable?.entityId ?? '',
|
||||
actionExecutor:
|
||||
smartSceneBloc.smartSceneEnable?.actionExecutor ?? '',
|
||||
executorProperty: null)
|
||||
],
|
||||
);
|
||||
sceneBloc.add(CreateSceneWithTasksEvent(
|
||||
createSceneModel: null,
|
||||
updateScene: updateScene,
|
||||
sceneId: sceneId,
|
||||
createAutomationModel: createAutomationModel,
|
||||
));
|
||||
Navigator.pop(context);
|
||||
}
|
||||
],
|
||||
);
|
||||
sceneBloc.add(CreateSceneWithTasksEvent(
|
||||
createSceneModel: null,
|
||||
updateScene: updateScene,
|
||||
sceneId: sceneId,
|
||||
createAutomationModel: createAutomationModel,
|
||||
));
|
||||
} else {
|
||||
if (isOnlyDelayOrDelayLast(actions)) {
|
||||
Navigator.pop(context);
|
||||
context.showCustomSnackbar(
|
||||
message: 'A single delay or delay-last operations are NOT allowed.',
|
||||
icon: const Icon(
|
||||
Icons.error,
|
||||
color: Colors.red,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
// Handle Scene Creation
|
||||
final createSceneModel = CreateSceneModel(
|
||||
unitUuid: HomeCubit.getInstance().selectedSpace!.id ?? '',
|
||||
sceneName: sceneName.text,
|
||||
decisionExpr: 'and',
|
||||
actions: [
|
||||
...List.generate(
|
||||
actions.length,
|
||||
(index) {
|
||||
final task = actions[index];
|
||||
if (task.deviceId == 'delay') {
|
||||
return CreateSceneAction(
|
||||
entityId: actions[index].deviceId,
|
||||
actionExecutor: 'delay',
|
||||
executorProperty: CreateSceneExecutorProperty(
|
||||
functionCode: '',
|
||||
functionValue: '',
|
||||
delaySeconds: task.functionValue,
|
||||
),
|
||||
);
|
||||
}
|
||||
final createSceneModel = CreateSceneModel(
|
||||
unitUuid: HomeCubit.getInstance().selectedSpace!.id ?? '',
|
||||
sceneName: sceneName.text,
|
||||
decisionExpr: 'and',
|
||||
actions: [
|
||||
...List.generate(
|
||||
actions.length,
|
||||
(index) {
|
||||
final task = actions[index];
|
||||
if (task.deviceId == 'delay') {
|
||||
return CreateSceneAction(
|
||||
entityId: task.deviceId,
|
||||
actionExecutor: 'device_issue',
|
||||
entityId: actions[index].deviceId,
|
||||
actionExecutor: 'delay',
|
||||
executorProperty: CreateSceneExecutorProperty(
|
||||
functionCode: task.code,
|
||||
functionValue: task.functionValue,
|
||||
delaySeconds: 0,
|
||||
functionCode: '',
|
||||
functionValue: '',
|
||||
delaySeconds: task.functionValue,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
if (smartSceneBloc.smartSceneEnable != null)
|
||||
CreateSceneAction(
|
||||
entityId: smartSceneBloc.smartSceneEnable?.entityId ?? '',
|
||||
actionExecutor:
|
||||
smartSceneBloc.smartSceneEnable?.actionExecutor ?? '',
|
||||
executorProperty: null)
|
||||
],
|
||||
);
|
||||
sceneBloc.add(CreateSceneWithTasksEvent(
|
||||
createSceneModel: createSceneModel,
|
||||
createAutomationModel: null,
|
||||
updateScene: updateScene,
|
||||
sceneId: sceneId,
|
||||
));
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}
|
||||
if (task.code == CreateSceneEnum.smartSceneSelect.name) {
|
||||
return CreateSceneAction(
|
||||
entityId: smartSceneBloc.smartSceneEnable?.entityId ?? '',
|
||||
actionExecutor:
|
||||
smartSceneBloc.smartSceneEnable?.actionExecutor ?? '',
|
||||
executorProperty: null);
|
||||
}
|
||||
return CreateSceneAction(
|
||||
entityId: task.deviceId,
|
||||
actionExecutor: 'device_issue',
|
||||
executorProperty: CreateSceneExecutorProperty(
|
||||
functionCode: task.code,
|
||||
functionValue: task.functionValue,
|
||||
delaySeconds: 0,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
sceneBloc.add(CreateSceneWithTasksEvent(
|
||||
createSceneModel: createSceneModel,
|
||||
createAutomationModel: null,
|
||||
updateScene: updateScene,
|
||||
sceneId: sceneId,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,12 +102,18 @@ class CreateSceneAction {
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'entityId': entityId,
|
||||
'actionExecutor': actionExecutor,
|
||||
if (executorProperty != null)
|
||||
if (executorProperty != null) {
|
||||
return {
|
||||
'entityId': entityId,
|
||||
'actionExecutor': actionExecutor,
|
||||
'executorProperty': executorProperty?.toMap(actionExecutor),
|
||||
};
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
'entityId': entityId,
|
||||
'actionExecutor': actionExecutor,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
factory CreateSceneAction.fromMap(Map<String, dynamic> map) {
|
||||
|
@ -1,16 +1,22 @@
|
||||
class SmartSceneEnable {
|
||||
final String entityId;
|
||||
final String actionExecutor;
|
||||
final String sceneORAutomationName;
|
||||
final bool isAutomation;
|
||||
|
||||
SmartSceneEnable({
|
||||
required this.entityId,
|
||||
required this.actionExecutor,
|
||||
required this.sceneORAutomationName,
|
||||
required this.isAutomation,
|
||||
});
|
||||
|
||||
factory SmartSceneEnable.fromJson(Map<String, dynamic> json) {
|
||||
return SmartSceneEnable(
|
||||
entityId: json['entityId'],
|
||||
actionExecutor: json['actionExecutor'],
|
||||
sceneORAutomationName: json['sceneORAutomationName'],
|
||||
isAutomation: json['isAutomation'],
|
||||
);
|
||||
}
|
||||
|
||||
@ -18,6 +24,8 @@ class SmartSceneEnable {
|
||||
return {
|
||||
'entityId': entityId,
|
||||
'actionExecutor': actionExecutor,
|
||||
'sceneORAutomationName': sceneORAutomationName,
|
||||
'isAutomation': isAutomation,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,13 @@ class SceneTasksView extends StatelessWidget {
|
||||
? sceneSettings.sceneName
|
||||
: StringsManager.createScene,
|
||||
padding: EdgeInsets.zero,
|
||||
leading: IconButton(
|
||||
onPressed: () {
|
||||
navigateToRoute(context, Routes.homeRoute);
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.arrow_back_ios,
|
||||
)),
|
||||
actions: [
|
||||
Visibility(
|
||||
visible: sceneSettings.sceneType.isNotEmpty,
|
||||
|
@ -1,4 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
|
||||
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
|
||||
import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart';
|
||||
import 'package:syncrow_app/features/scene/widgets/select_smart_scene/smart_enable_autoamtion.dart';
|
||||
import 'package:syncrow_app/features/scene/widgets/select_smart_scene/smart_enable_tab_run.dart';
|
||||
@ -15,6 +18,7 @@ class SmartAutomationSelectView extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final sceneType = context.read<CreateSceneBloc>().sceneType;
|
||||
return DefaultScaffold(
|
||||
title: "Select Smart Scene",
|
||||
padding: const EdgeInsets.only(top: 24),
|
||||
@ -25,28 +29,38 @@ class SmartAutomationSelectView extends StatelessWidget {
|
||||
icon: const Icon(
|
||||
Icons.arrow_back_ios,
|
||||
)),
|
||||
height: 260,
|
||||
height: sceneType.name == CreateSceneEnum.deviceStatusChanges.name
|
||||
? 260
|
||||
: 200,
|
||||
child: DefaultContainer(
|
||||
width: double.infinity,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SceneListTile(
|
||||
assetPath: Assets.handClickIcon,
|
||||
titleString: "Tap To Run",
|
||||
subtitleString: '',
|
||||
trailingWidget: const Icon(
|
||||
Icons.arrow_forward_ios_rounded,
|
||||
color: ColorsManager.greyColor,
|
||||
Visibility(
|
||||
visible:
|
||||
sceneType.name == CreateSceneEnum.deviceStatusChanges.name,
|
||||
child: SceneListTile(
|
||||
assetPath: Assets.handClickIcon,
|
||||
titleString: "Tap To Run",
|
||||
subtitleString: '',
|
||||
trailingWidget: const Icon(
|
||||
Icons.arrow_forward_ios_rounded,
|
||||
color: ColorsManager.greyColor,
|
||||
),
|
||||
onPressed: () {
|
||||
context.customBottomSheet(
|
||||
child: const SmartEnableTabRun(),
|
||||
);
|
||||
},
|
||||
),
|
||||
onPressed: () {
|
||||
context.customBottomSheet(
|
||||
child: const SmartEnableTabRun(),
|
||||
);
|
||||
},
|
||||
),
|
||||
const Divider(
|
||||
color: ColorsManager.dividerColor,
|
||||
Visibility(
|
||||
visible:
|
||||
sceneType.name == CreateSceneEnum.deviceStatusChanges.name,
|
||||
child: const Divider(
|
||||
color: ColorsManager.dividerColor,
|
||||
),
|
||||
),
|
||||
SceneListTile(
|
||||
assetPath: Assets.refreshIcon,
|
||||
|
@ -8,6 +8,7 @@ import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart
|
||||
import 'package:syncrow_app/navigation/navigate_to_route.dart';
|
||||
import 'package:syncrow_app/navigation/routing_constants.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class CreateSceneSaveButton extends StatefulWidget {
|
||||
@ -57,13 +58,7 @@ class _CreateSceneSaveButtonState extends State<CreateSceneSaveButton>
|
||||
sceneNameController.text = '';
|
||||
}
|
||||
} else if (state is CreateSceneError) {
|
||||
context.showCustomSnackbar(
|
||||
message: state.message,
|
||||
icon: const Icon(
|
||||
Icons.error,
|
||||
color: Colors.red,
|
||||
),
|
||||
);
|
||||
CustomSnackBar.displaySnackBar(state.message);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
@ -106,6 +101,7 @@ class _CreateSceneSaveButtonState extends State<CreateSceneSaveButton>
|
||||
),
|
||||
title: 'Scene Name',
|
||||
onConfirm: () {
|
||||
Navigator.pop(context);
|
||||
if (sceneNameController.text.isNotEmpty) {
|
||||
handleSaveButtonPress(
|
||||
context,
|
||||
|
@ -27,94 +27,164 @@ class IFDefaultContainer extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final sceneType = context.read<CreateSceneBloc>().sceneType;
|
||||
return DefaultContainer(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 2),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SceneListTile(
|
||||
leadingWidget: InkWell(
|
||||
onTap: () {
|
||||
if (sceneType.name ==
|
||||
CreateSceneEnum.deviceStatusChanges.name) {
|
||||
context.customAlertDialog(
|
||||
hideConfirmButton: true,
|
||||
alertBody: Column(
|
||||
children: [
|
||||
ListTile(
|
||||
title: const BodyMedium(
|
||||
text: "When all conditions are met"),
|
||||
onTap: () {
|
||||
context.read<CreateSceneBloc>().add(
|
||||
const SelectConditionEvent(
|
||||
"When all conditions are met"));
|
||||
Navigator.pop(context);
|
||||
return BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
||||
builder: (context, state) {
|
||||
final sceneType = context.read<CreateSceneBloc>().sceneType;
|
||||
return DefaultContainer(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 2),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SceneListTile(
|
||||
leadingWidget: InkWell(
|
||||
onTap: () {
|
||||
if (sceneType.name ==
|
||||
CreateSceneEnum.deviceStatusChanges.name) {
|
||||
context.customAlertDialog(
|
||||
hideConfirmButton: true,
|
||||
alertBody: Column(
|
||||
children: [
|
||||
ListTile(
|
||||
title: const BodyMedium(
|
||||
text: "When all conditions are met"),
|
||||
onTap: () {
|
||||
context.read<CreateSceneBloc>().add(
|
||||
const SelectConditionEvent(
|
||||
"When all conditions are met"));
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: const BodyMedium(
|
||||
text: "When any condition is met"),
|
||||
onTap: () {
|
||||
context.read<CreateSceneBloc>().add(
|
||||
const SelectConditionEvent(
|
||||
"When any condition is met"));
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
title: 'Conditions Rule',
|
||||
onConfirm: () {},
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
BodyLarge(
|
||||
text: 'IF',
|
||||
style: context.bodyLarge.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: ColorsManager.primaryTextColor,
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: sceneType.name ==
|
||||
CreateSceneEnum.deviceStatusChanges.name,
|
||||
child: BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
||||
builder: (context, state) {
|
||||
String conditionText = "When any condition is met";
|
||||
if (state is AddSceneTask) {
|
||||
if (state.condition == 'or') {
|
||||
conditionText = "When any condition is met";
|
||||
} else {
|
||||
conditionText = "When all conditions are met";
|
||||
}
|
||||
}
|
||||
return SizedBox(
|
||||
width: context.width * 0.6,
|
||||
child: Row(children: [
|
||||
BodySmall(text: conditionText),
|
||||
const Icon(Icons.keyboard_arrow_down)
|
||||
]),
|
||||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: const BodyMedium(
|
||||
text: "When any condition is met"),
|
||||
onTap: () {
|
||||
context.read<CreateSceneBloc>().add(
|
||||
const SelectConditionEvent(
|
||||
"When any condition is met"));
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
trailingWidget: BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
||||
builder: (context, state) {
|
||||
bool isClickable = false;
|
||||
if (state is AddSceneTask) {
|
||||
isClickable =
|
||||
state.automationTasksList?.isNotEmpty ?? false;
|
||||
}
|
||||
return GestureDetector(
|
||||
onTap: isClickable
|
||||
? () => Navigator.pushNamed(
|
||||
context,
|
||||
Routes.sceneControlDevicesRoute,
|
||||
arguments: SceneSettingsRouteArguments(
|
||||
sceneType:
|
||||
CreateSceneEnum.deviceStatusChanges.name,
|
||||
sceneId: '',
|
||||
sceneName: '',
|
||||
),
|
||||
)
|
||||
: null,
|
||||
child: SvgPicture.asset(
|
||||
Assets.addIcon,
|
||||
colorFilter: ColorFilter.mode(
|
||||
isClickable
|
||||
? ColorsManager.primaryColor
|
||||
: ColorsManager.greyColor,
|
||||
BlendMode.srcIn,
|
||||
),
|
||||
],
|
||||
),
|
||||
title: 'Conditions Rule',
|
||||
onConfirm: () {},
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
BodyLarge(
|
||||
text: 'IF',
|
||||
style: context.bodyLarge.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: ColorsManager.primaryTextColor,
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: sceneType.name ==
|
||||
CreateSceneEnum.deviceStatusChanges.name,
|
||||
child: BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
||||
builder: (context, state) {
|
||||
String conditionText = "When any condition is met";
|
||||
if (state is AddSceneTask) {
|
||||
if (state.condition == 'or') {
|
||||
conditionText = "When any condition is met";
|
||||
} else {
|
||||
conditionText = "When all conditions are met";
|
||||
}
|
||||
}
|
||||
return SizedBox(
|
||||
width: context.width * 0.6,
|
||||
child: Row(children: [
|
||||
BodySmall(text: conditionText),
|
||||
const Icon(Icons.keyboard_arrow_down)
|
||||
]),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
padding: EdgeInsets.zero,
|
||||
),
|
||||
),
|
||||
trailingWidget: BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
||||
builder: (context, state) {
|
||||
bool isClickable = false;
|
||||
if (state is AddSceneTask) {
|
||||
isClickable = state.automationTasksList?.isNotEmpty ?? false;
|
||||
}
|
||||
return GestureDetector(
|
||||
onTap: isClickable
|
||||
? () => Navigator.pushNamed(
|
||||
const LightDivider(),
|
||||
BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
||||
builder: (context, state) {
|
||||
if (state is AddSceneTask) {
|
||||
final automationTasksList = state.automationTasksList;
|
||||
if (automationTasksList?.isNotEmpty == true) {
|
||||
return ListView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: automationTasksList?.length,
|
||||
reverse: true,
|
||||
itemBuilder: (context, index) {
|
||||
return ThenAddedTasksContainer(
|
||||
taskItem: automationTasksList![index],
|
||||
isAutomation: true,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
final sceneType = context.read<CreateSceneBloc>().sceneType;
|
||||
if (sceneType.name == CreateSceneEnum.tabToRun.name) {
|
||||
return const SceneListTile(
|
||||
padding: EdgeInsets.symmetric(horizontal: 2),
|
||||
assetPath: Assets.handClickIcon,
|
||||
titleString: StringsManager.tapToRun,
|
||||
subtitleString: '',
|
||||
);
|
||||
}
|
||||
return SceneListTile(
|
||||
titleString: '+ Add Condition',
|
||||
textAlign: TextAlign.center,
|
||||
onPressed: () {
|
||||
final sceneType =
|
||||
context.read<CreateSceneBloc>().sceneType;
|
||||
if (sceneType.name == CreateSceneEnum.none.name) {
|
||||
Navigator.push(
|
||||
context,
|
||||
CustomPageRoute(
|
||||
builder: (context) =>
|
||||
const CreateSceneView()));
|
||||
} else {
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
Routes.sceneControlDevicesRoute,
|
||||
arguments: SceneSettingsRouteArguments(
|
||||
@ -123,77 +193,15 @@ class IFDefaultContainer extends StatelessWidget {
|
||||
sceneId: '',
|
||||
sceneName: '',
|
||||
),
|
||||
)
|
||||
: null,
|
||||
child: SvgPicture.asset(
|
||||
Assets.addIcon,
|
||||
colorFilter: ColorFilter.mode(
|
||||
isClickable
|
||||
? ColorsManager.primaryColor
|
||||
: ColorsManager.greyColor,
|
||||
BlendMode.srcIn,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
padding: EdgeInsets.zero,
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
const LightDivider(),
|
||||
BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
||||
builder: (context, state) {
|
||||
if (state is AddSceneTask) {
|
||||
final automationTasksList = state.automationTasksList;
|
||||
if (automationTasksList?.isNotEmpty == true) {
|
||||
return ListView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: automationTasksList?.length,
|
||||
reverse: true,
|
||||
itemBuilder: (context, index) {
|
||||
return ThenAddedTasksContainer(
|
||||
taskItem: automationTasksList![index],
|
||||
isAutomation: true,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
final sceneType = context.read<CreateSceneBloc>().sceneType;
|
||||
if (sceneType.name == CreateSceneEnum.tabToRun.name) {
|
||||
return const SceneListTile(
|
||||
padding: EdgeInsets.symmetric(horizontal: 2),
|
||||
assetPath: Assets.handClickIcon,
|
||||
titleString: StringsManager.tapToRun,
|
||||
subtitleString: '',
|
||||
);
|
||||
}
|
||||
return SceneListTile(
|
||||
titleString: '+ Add Condition',
|
||||
textAlign: TextAlign.center,
|
||||
onPressed: () {
|
||||
final sceneType = context.read<CreateSceneBloc>().sceneType;
|
||||
if (sceneType.name == CreateSceneEnum.none.name) {
|
||||
Navigator.push(
|
||||
context,
|
||||
CustomPageRoute(
|
||||
builder: (context) => const CreateSceneView()));
|
||||
} else {
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
Routes.sceneControlDevicesRoute,
|
||||
arguments: SceneSettingsRouteArguments(
|
||||
sceneType: CreateSceneEnum.deviceStatusChanges.name,
|
||||
sceneId: '',
|
||||
sceneName: '',
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
|
||||
import 'package:syncrow_app/features/scene/enum/create_scene_enum.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';
|
||||
@ -62,58 +63,63 @@ class ThenAddedTasksContainer extends StatelessWidget
|
||||
operationValue = functionValue.toString();
|
||||
}
|
||||
return DefaultContainer(
|
||||
onTap: () {
|
||||
List<SceneStaticFunction> functionOperation = [];
|
||||
onTap: taskItem.code == CreateSceneEnum.smartSceneSelect.name
|
||||
? null
|
||||
: () {
|
||||
List<SceneStaticFunction> functionOperation = [];
|
||||
|
||||
/// get the task functions
|
||||
functionOperation = List.from(getOperationsForOneFunction(
|
||||
taskItem: taskItem,
|
||||
deviceId: taskItem.deviceId,
|
||||
isAutomation: isAutomation ?? false));
|
||||
/// get the task functions
|
||||
functionOperation = List.from(getOperationsForOneFunction(
|
||||
taskItem: taskItem,
|
||||
deviceId: taskItem.deviceId,
|
||||
isAutomation: isAutomation ?? false));
|
||||
|
||||
/// show alert dialog based on type
|
||||
context.customAlertDialog(
|
||||
alertBody: getTheCorrectDialogBody(functionOperation.first, null,
|
||||
isAutomation: isAutomation ?? false),
|
||||
title: functionOperation.first.operationName,
|
||||
onConfirm: () {
|
||||
final savedCode = functionOperation.first.deviceId.contains('delay')
|
||||
? 'delay'
|
||||
: functionOperation.first.code;
|
||||
if (isAutomation == true) {
|
||||
final automationSelectedValue =
|
||||
createSceneBloc.automationSelectedValues[savedCode];
|
||||
/// show alert dialog based on type
|
||||
context.customAlertDialog(
|
||||
alertBody: getTheCorrectDialogBody(
|
||||
functionOperation.first, null,
|
||||
isAutomation: isAutomation ?? false),
|
||||
title: functionOperation.first.operationName,
|
||||
onConfirm: () {
|
||||
final savedCode =
|
||||
functionOperation.first.deviceId.contains('delay')
|
||||
? 'delay'
|
||||
: functionOperation.first.code;
|
||||
if (isAutomation == true) {
|
||||
final automationSelectedValue =
|
||||
createSceneBloc.automationSelectedValues[savedCode];
|
||||
|
||||
try {
|
||||
createSceneBloc.add(
|
||||
UpdateTaskEvent(
|
||||
newValue: automationSelectedValue,
|
||||
taskId: taskItem.uniqueCustomId,
|
||||
isAutomation: true,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
debugPrint('Error adding UpdateTaskEvent: $e');
|
||||
}
|
||||
} else {
|
||||
final selectedValue = createSceneBloc.selectedValues[savedCode];
|
||||
try {
|
||||
createSceneBloc.add(
|
||||
UpdateTaskEvent(
|
||||
newValue: automationSelectedValue,
|
||||
taskId: taskItem.uniqueCustomId,
|
||||
isAutomation: true,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
debugPrint('Error adding UpdateTaskEvent: $e');
|
||||
}
|
||||
} else {
|
||||
final selectedValue =
|
||||
createSceneBloc.selectedValues[savedCode];
|
||||
|
||||
try {
|
||||
createSceneBloc.add(
|
||||
UpdateTaskEvent(
|
||||
newValue: selectedValue,
|
||||
taskId: taskItem.uniqueCustomId,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
debugPrint('Error adding UpdateTaskEvent: $e');
|
||||
}
|
||||
}
|
||||
try {
|
||||
createSceneBloc.add(
|
||||
UpdateTaskEvent(
|
||||
newValue: selectedValue,
|
||||
taskId: taskItem.uniqueCustomId,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
debugPrint('Error adding UpdateTaskEvent: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
},
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
},
|
||||
padding: EdgeInsets.zero,
|
||||
child: Dismissible(
|
||||
key: Key(taskItem.uniqueCustomId.toString()),
|
||||
@ -171,12 +177,20 @@ class ThenAddedTasksContainer extends StatelessWidget
|
||||
subtitleWidget: Row(
|
||||
children: [
|
||||
BodyMedium(
|
||||
text: "${taskItem.operationName}: ",
|
||||
text: taskItem.code == CreateSceneEnum.smartSceneSelect.name
|
||||
? taskItem.icon.contains('player')
|
||||
? 'Automation: '
|
||||
: "Tab-To-Run: "
|
||||
: "${taskItem.operationName}: ",
|
||||
fontColor: ColorsManager.secondaryTextColor,
|
||||
fontWeight: FontWeight.normal,
|
||||
),
|
||||
BodyMedium(
|
||||
text: operationValue,
|
||||
text: taskItem.code == CreateSceneEnum.smartSceneSelect.name
|
||||
? taskItem.operationName == 'rule_enable'
|
||||
? 'Enable'
|
||||
: "Disable"
|
||||
: operationValue,
|
||||
fontColor: ColorsManager.secondaryTextColor,
|
||||
fontWeight: FontWeight.normal,
|
||||
),
|
||||
|
@ -125,6 +125,7 @@ class _SmartSceneSelectAutomationListState
|
||||
alertBody: EnableDisableAutomationDialog(
|
||||
automationId: automation.id,
|
||||
descriptionSelected: descriptionSelected,
|
||||
sceneORAutomationName: automation.name,
|
||||
),
|
||||
title: automation.name,
|
||||
onConfirm: () {
|
||||
@ -157,6 +158,7 @@ class _SmartSceneSelectAutomationListState
|
||||
alertBody: EnableDisableAutomationDialog(
|
||||
automationId: automation.id,
|
||||
descriptionSelected: descriptionSelected,
|
||||
sceneORAutomationName: automation.name,
|
||||
),
|
||||
title: automation.name,
|
||||
onConfirm: () {
|
||||
@ -191,10 +193,12 @@ class EnableDisableAutomationDialog extends StatefulWidget {
|
||||
super.key,
|
||||
required this.automationId,
|
||||
required this.descriptionSelected,
|
||||
required this.sceneORAutomationName,
|
||||
});
|
||||
|
||||
final String automationId;
|
||||
final String descriptionSelected;
|
||||
final String sceneORAutomationName;
|
||||
|
||||
@override
|
||||
State<EnableDisableAutomationDialog> createState() =>
|
||||
@ -251,9 +255,11 @@ class _EnableDisableAutomationDialogState
|
||||
.read<SmartSceneSelectBloc>()
|
||||
.add(SmartSceneEnableEvent(
|
||||
SmartSceneEnable(
|
||||
entityId: widget.automationId,
|
||||
actionExecutor: value!,
|
||||
),
|
||||
entityId: widget.automationId,
|
||||
actionExecutor: value!,
|
||||
sceneORAutomationName:
|
||||
widget.sceneORAutomationName,
|
||||
isAutomation: true),
|
||||
));
|
||||
},
|
||||
),
|
||||
@ -267,6 +273,8 @@ class _EnableDisableAutomationDialogState
|
||||
SmartSceneEnable(
|
||||
entityId: widget.automationId,
|
||||
actionExecutor: operation.value,
|
||||
sceneORAutomationName: widget.sceneORAutomationName,
|
||||
isAutomation: true,
|
||||
),
|
||||
));
|
||||
},
|
||||
|
@ -89,6 +89,8 @@ class _SmartSceneSelectTabToRunListState
|
||||
.add(SmartSceneEnableEvent(SmartSceneEnable(
|
||||
entityId: scene.id,
|
||||
actionExecutor: 'rule_enable',
|
||||
sceneORAutomationName: scene.name,
|
||||
isAutomation: false,
|
||||
)));
|
||||
}
|
||||
}),
|
||||
@ -101,6 +103,8 @@ class _SmartSceneSelectTabToRunListState
|
||||
.add(SmartSceneEnableEvent(SmartSceneEnable(
|
||||
entityId: scene.id,
|
||||
actionExecutor: 'rule_enable',
|
||||
sceneORAutomationName: scene.name,
|
||||
isAutomation: false,
|
||||
)));
|
||||
},
|
||||
);
|
||||
|
Reference in New Issue
Block a user