push autoamtion api connect

This commit is contained in:
ashrafzarkanisala
2024-07-24 01:41:10 +03:00
parent 9a088353e0
commit 7a773f1653
20 changed files with 874 additions and 272 deletions
@@ -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,