mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-25 14:57:55 +00:00
push autoamtion api connect
This commit is contained in:
@@ -24,7 +24,7 @@ class AlertDialogSliderSteps extends StatefulWidget {
|
||||
|
||||
class _AlertDialogSliderStepsState extends State<AlertDialogSliderSteps> {
|
||||
double? groupValue;
|
||||
int selectedToggleIndex = 0;
|
||||
int selectedToggleIndex = 1;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
@@ -33,23 +33,53 @@ class _AlertDialogSliderStepsState extends State<AlertDialogSliderSteps> {
|
||||
if (widget.isAutomation) {
|
||||
final automationTempTaskList =
|
||||
context.read<CreateSceneBloc>().automationTempTasksList;
|
||||
final automationComparatorValues =
|
||||
context.read<CreateSceneBloc>().automationComparatorValues;
|
||||
|
||||
if (automationTempTaskList.isNotEmpty) {
|
||||
for (var element in automationTempTaskList) {
|
||||
if (element.code == widget.taskItem.code) {
|
||||
groupValue = element.functionValue;
|
||||
} else {
|
||||
context.read<CreateSceneBloc>().add(RemoveFromSelectedValueById(
|
||||
code: widget.taskItem.code, isAutomation: widget.isAutomation));
|
||||
selectedToggleIndex =
|
||||
_comparatorToIndex(automationComparatorValues[element.code]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (widget.functionValue != null) {
|
||||
setState(() {
|
||||
groupValue = widget.functionValue;
|
||||
});
|
||||
groupValue = widget.functionValue;
|
||||
} else {
|
||||
groupValue = widget.taskItem.operationalValues[0].minValue;
|
||||
}
|
||||
if (widget.taskItem.comparator != null) {
|
||||
selectedToggleIndex = _comparatorToIndex(widget.taskItem.comparator);
|
||||
}
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
int _comparatorToIndex(String? comparator) {
|
||||
switch (comparator) {
|
||||
case "<=":
|
||||
return 0;
|
||||
case "==":
|
||||
return 1;
|
||||
case ">=":
|
||||
return 2;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
String _indexToComparator(int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return "<=";
|
||||
case 1:
|
||||
return "==";
|
||||
case 2:
|
||||
return ">=";
|
||||
default:
|
||||
return "==";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +98,10 @@ class _AlertDialogSliderStepsState extends State<AlertDialogSliderSteps> {
|
||||
setState(() {
|
||||
selectedToggleIndex = index;
|
||||
});
|
||||
context.read<CreateSceneBloc>().add(SelectedValueEvent(
|
||||
code: widget.taskItem.code,
|
||||
isAutomation: widget.isAutomation,
|
||||
comparator: _indexToComparator(selectedToggleIndex)));
|
||||
},
|
||||
borderRadius: BorderRadius.circular(30),
|
||||
selectedColor: Colors.white,
|
||||
@@ -164,7 +198,9 @@ class _AlertDialogSliderStepsState extends State<AlertDialogSliderSteps> {
|
||||
context.read<CreateSceneBloc>().add(SelectedValueEvent(
|
||||
value: groupValue,
|
||||
code: widget.taskItem.code,
|
||||
isAutomation: widget.isAutomation));
|
||||
isAutomation: widget.isAutomation,
|
||||
comparator:
|
||||
_indexToComparator(selectedToggleIndex)));
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
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/helper/scene_logic_helper.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_button.dart';
|
||||
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/resource_manager/color_manager.dart';
|
||||
|
||||
@@ -43,8 +46,7 @@ class _CreateSceneSaveButtonState extends State<CreateSceneSaveButton>
|
||||
listener: (context, state) {
|
||||
if (state is CreateSceneWithTasks) {
|
||||
if (state.success == true) {
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(context);
|
||||
navigateToRoute(context, Routes.homeRoute);
|
||||
context.showCustomSnackbar(
|
||||
message: 'Scene created successfully',
|
||||
icon: const Icon(
|
||||
@@ -66,55 +68,59 @@ class _CreateSceneSaveButtonState extends State<CreateSceneSaveButton>
|
||||
},
|
||||
builder: (context, state) {
|
||||
return DefaultButton(
|
||||
onPressed: widget.sceneName.isNotEmpty
|
||||
? () {
|
||||
final tasks = context.read<CreateSceneBloc>().tasksList;
|
||||
handleSaveButtonPress(
|
||||
context,
|
||||
sceneNameController,
|
||||
tasks,
|
||||
updateScene: true,
|
||||
sceneId: widget.sceneId,
|
||||
);
|
||||
}
|
||||
: () {
|
||||
context.customAlertDialog(
|
||||
alertBody: Padding(
|
||||
padding:
|
||||
const EdgeInsets.only(left: 8, right: 8, bottom: 8),
|
||||
child: SizedBox(
|
||||
height: 40,
|
||||
child: SearchBar(
|
||||
controller: sceneNameController,
|
||||
elevation: WidgetStateProperty.all(0),
|
||||
textStyle:
|
||||
WidgetStateProperty.all(context.bodyMedium),
|
||||
hintStyle: WidgetStateProperty.all(
|
||||
context.bodyMedium.copyWith(
|
||||
fontSize: 14,
|
||||
color: ColorsManager.secondaryTextColor),
|
||||
),
|
||||
hintText: 'Enter scene name',
|
||||
backgroundColor: WidgetStateProperty.all(
|
||||
ColorsManager.backgroundColor),
|
||||
),
|
||||
onPressed: () {
|
||||
final sceneBloc = context.read<CreateSceneBloc>();
|
||||
final isAutomation =
|
||||
sceneBloc.sceneType == CreateSceneEnum.deviceStatusChanges;
|
||||
|
||||
if (widget.sceneName.isNotEmpty) {
|
||||
handleSaveButtonPress(
|
||||
context,
|
||||
sceneName: sceneNameController,
|
||||
actions: sceneBloc.tasksList,
|
||||
updateScene: true,
|
||||
sceneId: widget.sceneId,
|
||||
isAutomation: isAutomation,
|
||||
conditions: sceneBloc.automationTasksList,
|
||||
);
|
||||
} else {
|
||||
context.customAlertDialog(
|
||||
alertBody: Padding(
|
||||
padding: const EdgeInsets.only(left: 8, right: 8, bottom: 8),
|
||||
child: SizedBox(
|
||||
height: 40,
|
||||
child: SearchBar(
|
||||
controller: sceneNameController,
|
||||
elevation: WidgetStateProperty.all(0),
|
||||
textStyle: WidgetStateProperty.all(context.bodyMedium),
|
||||
hintStyle: WidgetStateProperty.all(
|
||||
context.bodyMedium.copyWith(
|
||||
fontSize: 14,
|
||||
color: ColorsManager.secondaryTextColor),
|
||||
),
|
||||
hintText: 'Enter scene name',
|
||||
backgroundColor: WidgetStateProperty.all(
|
||||
ColorsManager.backgroundColor),
|
||||
),
|
||||
title: 'Scene Name',
|
||||
onConfirm: () {
|
||||
if (sceneNameController.text.isNotEmpty) {
|
||||
final tasks = context.read<CreateSceneBloc>().tasksList;
|
||||
handleSaveButtonPress(
|
||||
context,
|
||||
sceneNameController,
|
||||
tasks,
|
||||
updateScene: false,
|
||||
sceneId: widget.sceneId,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
),
|
||||
),
|
||||
title: 'Scene Name',
|
||||
onConfirm: () {
|
||||
if (sceneNameController.text.isNotEmpty) {
|
||||
handleSaveButtonPress(
|
||||
context,
|
||||
sceneName: sceneNameController,
|
||||
actions: sceneBloc.tasksList,
|
||||
updateScene: false,
|
||||
sceneId: widget.sceneId,
|
||||
isAutomation: isAutomation,
|
||||
conditions: sceneBloc.automationTasksList,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
customButtonStyle: ButtonStyle(
|
||||
backgroundColor: WidgetStateProperty.all<Color>(
|
||||
ColorsManager.primaryColor,
|
||||
|
||||
@@ -1,18 +1,24 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.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/model/scene_settings_route_arguments.dart';
|
||||
import 'package:syncrow_app/features/scene/view/create_scene_view.dart';
|
||||
import 'package:syncrow_app/features/scene/widgets/if_then_containers/then_added_tasks.dart';
|
||||
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/light_divider.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.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/helpers/custom_page_route.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/strings_manager.dart';
|
||||
|
||||
class IFDefaultContainer extends StatelessWidget {
|
||||
const IFDefaultContainer({
|
||||
@@ -27,30 +33,101 @@ class IFDefaultContainer extends StatelessWidget {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SceneListTile(
|
||||
leadingWidget: BodyLarge(
|
||||
text: 'IF',
|
||||
style: context.bodyLarge.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: ColorsManager.primaryTextColor,
|
||||
leadingWidget: InkWell(
|
||||
onTap: () {
|
||||
final sceneType = context.read<CreateSceneBloc>().sceneType;
|
||||
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,
|
||||
),
|
||||
),
|
||||
BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
||||
builder: (context, state) {
|
||||
String conditionText = "When any condition is met";
|
||||
if (state is ConditionSelectedState) {
|
||||
conditionText = state.condition;
|
||||
}
|
||||
return SizedBox(
|
||||
width: context.width * 0.6,
|
||||
child: Row(children: [
|
||||
BodySmall(text: conditionText),
|
||||
const Icon(Icons.keyboard_arrow_down)
|
||||
]),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
trailingWidget: GestureDetector(
|
||||
onTap: () => Navigator.pushNamed(
|
||||
context,
|
||||
Routes.sceneControlDevicesRoute,
|
||||
arguments: SceneSettingsRouteArguments(
|
||||
sceneType: CreateSceneEnum.deviceStatusChanges.name,
|
||||
sceneId: '',
|
||||
sceneName: '',
|
||||
),
|
||||
),
|
||||
child: SvgPicture.asset(
|
||||
Assets.addIcon,
|
||||
colorFilter: const ColorFilter.mode(
|
||||
ColorsManager.primaryColor,
|
||||
BlendMode.srcIn,
|
||||
),
|
||||
),
|
||||
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,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
padding: EdgeInsets.zero,
|
||||
),
|
||||
@@ -74,19 +151,36 @@ class IFDefaultContainer extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
final sceneType = context.read<CreateSceneBloc>().sceneType;
|
||||
if (sceneType.name == CreateSceneEnum.tabToRun.name) {
|
||||
return const SceneListTile(
|
||||
assetPath: Assets.handClickIcon,
|
||||
titleString: StringsManager.tapToRun,
|
||||
subtitleString: '',
|
||||
);
|
||||
}
|
||||
return SceneListTile(
|
||||
titleString: '+ Add Condition',
|
||||
textAlign: TextAlign.center,
|
||||
onPressed: () => Navigator.pushNamed(
|
||||
context,
|
||||
Routes.sceneControlDevicesRoute,
|
||||
arguments: SceneSettingsRouteArguments(
|
||||
sceneType: CreateSceneEnum.deviceStatusChanges.name,
|
||||
sceneId: '',
|
||||
sceneName: '',
|
||||
),
|
||||
),
|
||||
);
|
||||
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: '',
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
)
|
||||
],
|
||||
|
||||
@@ -2,6 +2,8 @@ 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/view/create_scene_view.dart';
|
||||
import 'package:syncrow_app/features/scene/widgets/if_then_containers/then_added_tasks.dart';
|
||||
import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart';
|
||||
import 'package:syncrow_app/features/scene/widgets/bottom_sheet_widget.dart';
|
||||
@@ -10,6 +12,7 @@ import 'package:syncrow_app/features/shared_widgets/light_divider.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
import 'package:syncrow_app/utils/helpers/custom_page_route.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class ThenDefaultContainer extends StatelessWidget {
|
||||
@@ -35,17 +38,29 @@ class ThenDefaultContainer extends StatelessWidget {
|
||||
color: ColorsManager.primaryTextColor,
|
||||
),
|
||||
),
|
||||
trailingWidget: GestureDetector(
|
||||
onTap: () => context.customBottomSheet(
|
||||
child: const CustomBottomSheetWidget(),
|
||||
),
|
||||
child: SvgPicture.asset(
|
||||
Assets.addIcon,
|
||||
colorFilter: const ColorFilter.mode(
|
||||
ColorsManager.primaryColor,
|
||||
BlendMode.srcIn,
|
||||
),
|
||||
),
|
||||
trailingWidget: BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
||||
builder: (context, state) {
|
||||
bool isClickable = false;
|
||||
if (state is AddSceneTask) {
|
||||
isClickable = state.tasksList.isNotEmpty;
|
||||
}
|
||||
return GestureDetector(
|
||||
onTap: isClickable
|
||||
? () => context.customBottomSheet(
|
||||
child: const CustomBottomSheetWidget(),
|
||||
)
|
||||
: null,
|
||||
child: SvgPicture.asset(
|
||||
Assets.addIcon,
|
||||
colorFilter: ColorFilter.mode(
|
||||
isClickable
|
||||
? ColorsManager.primaryColor
|
||||
: ColorsManager.greyColor,
|
||||
BlendMode.srcIn,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
padding: EdgeInsets.zero,
|
||||
),
|
||||
@@ -71,20 +86,23 @@ class ThenDefaultContainer extends StatelessWidget {
|
||||
},
|
||||
);
|
||||
}
|
||||
return SceneListTile(
|
||||
titleString: '+ Add Task',
|
||||
textAlign: TextAlign.center,
|
||||
onPressed: () => context.customBottomSheet(
|
||||
child: const CustomBottomSheetWidget(),
|
||||
),
|
||||
);
|
||||
}
|
||||
return SceneListTile(
|
||||
titleString: '+ Add Task',
|
||||
textAlign: TextAlign.center,
|
||||
onPressed: () => context.customBottomSheet(
|
||||
child: const CustomBottomSheetWidget(),
|
||||
),
|
||||
onPressed: () {
|
||||
final sceneType = context.read<CreateSceneBloc>().sceneType;
|
||||
if (sceneType.name == CreateSceneEnum.none.name) {
|
||||
Navigator.push(
|
||||
context,
|
||||
CustomPageRoute(
|
||||
builder: (context) => const CreateSceneView()));
|
||||
} else {
|
||||
context.customBottomSheet(
|
||||
child: const CustomBottomSheetWidget(),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user