mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-27 02:14:55 +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(
|
||||
|
||||
@ -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,10 +33,7 @@ mixin SceneLogicHelper {
|
||||
final sceneBloc = context.read<CreateSceneBloc>();
|
||||
final smartSceneBloc = context.read<SmartSceneSelectBloc>();
|
||||
|
||||
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(
|
||||
@ -43,7 +41,10 @@ mixin SceneLogicHelper {
|
||||
color: Colors.red,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isAutomation) {
|
||||
final createAutomationModel = CreateAutomationModel(
|
||||
unitUuid: HomeCubit.getInstance().selectedSpace!.id ?? '',
|
||||
automationName: sceneName.text,
|
||||
@ -82,6 +83,13 @@ mixin SceneLogicHelper {
|
||||
),
|
||||
);
|
||||
}
|
||||
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',
|
||||
@ -93,12 +101,6 @@ mixin SceneLogicHelper {
|
||||
);
|
||||
},
|
||||
),
|
||||
if (smartSceneBloc.smartSceneEnable != null)
|
||||
CreateSceneAction(
|
||||
entityId: smartSceneBloc.smartSceneEnable?.entityId ?? '',
|
||||
actionExecutor:
|
||||
smartSceneBloc.smartSceneEnable?.actionExecutor ?? '',
|
||||
executorProperty: null)
|
||||
],
|
||||
);
|
||||
sceneBloc.add(CreateSceneWithTasksEvent(
|
||||
@ -107,20 +109,7 @@ mixin SceneLogicHelper {
|
||||
sceneId: sceneId,
|
||||
createAutomationModel: createAutomationModel,
|
||||
));
|
||||
Navigator.pop(context);
|
||||
}
|
||||
} 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,
|
||||
@ -141,6 +130,13 @@ mixin SceneLogicHelper {
|
||||
),
|
||||
);
|
||||
}
|
||||
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',
|
||||
@ -152,12 +148,6 @@ mixin SceneLogicHelper {
|
||||
);
|
||||
},
|
||||
),
|
||||
if (smartSceneBloc.smartSceneEnable != null)
|
||||
CreateSceneAction(
|
||||
entityId: smartSceneBloc.smartSceneEnable?.entityId ?? '',
|
||||
actionExecutor:
|
||||
smartSceneBloc.smartSceneEnable?.actionExecutor ?? '',
|
||||
executorProperty: null)
|
||||
],
|
||||
);
|
||||
sceneBloc.add(CreateSceneWithTasksEvent(
|
||||
@ -166,8 +156,6 @@ mixin SceneLogicHelper {
|
||||
updateScene: updateScene,
|
||||
sceneId: sceneId,
|
||||
));
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -102,12 +102,18 @@ class CreateSceneAction {
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
if (executorProperty != null) {
|
||||
return {
|
||||
'entityId': entityId,
|
||||
'actionExecutor': actionExecutor,
|
||||
if (executorProperty != null)
|
||||
'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,13 +29,18 @@ 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(
|
||||
Visibility(
|
||||
visible:
|
||||
sceneType.name == CreateSceneEnum.deviceStatusChanges.name,
|
||||
child: SceneListTile(
|
||||
assetPath: Assets.handClickIcon,
|
||||
titleString: "Tap To Run",
|
||||
subtitleString: '',
|
||||
@ -45,9 +54,14 @@ class SmartAutomationSelectView extends StatelessWidget {
|
||||
);
|
||||
},
|
||||
),
|
||||
const Divider(
|
||||
),
|
||||
Visibility(
|
||||
visible:
|
||||
sceneType.name == CreateSceneEnum.deviceStatusChanges.name,
|
||||
child: const Divider(
|
||||
color: ColorsManager.dividerColor,
|
||||
),
|
||||
),
|
||||
SceneListTile(
|
||||
assetPath: Assets.refreshIcon,
|
||||
titleString: "Automation",
|
||||
|
||||
@ -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,6 +27,8 @@ class IFDefaultContainer extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
||||
builder: (context, state) {
|
||||
final sceneType = context.read<CreateSceneBloc>().sceneType;
|
||||
return DefaultContainer(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 2),
|
||||
@ -110,7 +112,8 @@ class IFDefaultContainer extends StatelessWidget {
|
||||
builder: (context, state) {
|
||||
bool isClickable = false;
|
||||
if (state is AddSceneTask) {
|
||||
isClickable = state.automationTasksList?.isNotEmpty ?? false;
|
||||
isClickable =
|
||||
state.automationTasksList?.isNotEmpty ?? false;
|
||||
}
|
||||
return GestureDetector(
|
||||
onTap: isClickable
|
||||
@ -172,18 +175,21 @@ class IFDefaultContainer extends StatelessWidget {
|
||||
titleString: '+ Add Condition',
|
||||
textAlign: TextAlign.center,
|
||||
onPressed: () {
|
||||
final sceneType = context.read<CreateSceneBloc>().sceneType;
|
||||
final sceneType =
|
||||
context.read<CreateSceneBloc>().sceneType;
|
||||
if (sceneType.name == CreateSceneEnum.none.name) {
|
||||
Navigator.push(
|
||||
context,
|
||||
CustomPageRoute(
|
||||
builder: (context) => const CreateSceneView()));
|
||||
builder: (context) =>
|
||||
const CreateSceneView()));
|
||||
} else {
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
Routes.sceneControlDevicesRoute,
|
||||
arguments: SceneSettingsRouteArguments(
|
||||
sceneType: CreateSceneEnum.deviceStatusChanges.name,
|
||||
sceneType:
|
||||
CreateSceneEnum.deviceStatusChanges.name,
|
||||
sceneId: '',
|
||||
sceneName: '',
|
||||
),
|
||||
@ -195,5 +201,7 @@ class IFDefaultContainer extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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,7 +63,9 @@ class ThenAddedTasksContainer extends StatelessWidget
|
||||
operationValue = functionValue.toString();
|
||||
}
|
||||
return DefaultContainer(
|
||||
onTap: () {
|
||||
onTap: taskItem.code == CreateSceneEnum.smartSceneSelect.name
|
||||
? null
|
||||
: () {
|
||||
List<SceneStaticFunction> functionOperation = [];
|
||||
|
||||
/// get the task functions
|
||||
@ -73,11 +76,13 @@ class ThenAddedTasksContainer extends StatelessWidget
|
||||
|
||||
/// show alert dialog based on type
|
||||
context.customAlertDialog(
|
||||
alertBody: getTheCorrectDialogBody(functionOperation.first, null,
|
||||
alertBody: getTheCorrectDialogBody(
|
||||
functionOperation.first, null,
|
||||
isAutomation: isAutomation ?? false),
|
||||
title: functionOperation.first.operationName,
|
||||
onConfirm: () {
|
||||
final savedCode = functionOperation.first.deviceId.contains('delay')
|
||||
final savedCode =
|
||||
functionOperation.first.deviceId.contains('delay')
|
||||
? 'delay'
|
||||
: functionOperation.first.code;
|
||||
if (isAutomation == true) {
|
||||
@ -96,7 +101,8 @@ class ThenAddedTasksContainer extends StatelessWidget
|
||||
debugPrint('Error adding UpdateTaskEvent: $e');
|
||||
}
|
||||
} else {
|
||||
final selectedValue = createSceneBloc.selectedValues[savedCode];
|
||||
final selectedValue =
|
||||
createSceneBloc.selectedValues[savedCode];
|
||||
|
||||
try {
|
||||
createSceneBloc.add(
|
||||
@ -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() =>
|
||||
@ -253,7 +257,9 @@ class _EnableDisableAutomationDialogState
|
||||
SmartSceneEnable(
|
||||
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