push put api

This commit is contained in:
ashrafzarkanisala
2024-07-01 01:57:13 +03:00
parent cc6b754845
commit c01d9034fd
16 changed files with 883 additions and 176 deletions

View File

@ -31,16 +31,17 @@ class _AlertDialogFunctionsOperationsBodyState
final tempTaskList = context.read<CreateSceneBloc>().tempTasksList;
if (tempTaskList.isEmpty) {
context.read<CreateSceneBloc>().add(const ClearTempTaskListEvent());
}
for (var element in tempTaskList) {
if (element.code == widget.functions[widget.index].code) {
groupValue = element.functionValue;
} else {
context.read<CreateSceneBloc>().add(RemoveFromSelectedValueById(
code: widget.functions[widget.index].code));
} else if (tempTaskList.isNotEmpty) {
for (var element in tempTaskList) {
if (element.code == widget.functions[widget.index].code) {
groupValue = element.functionValue;
} else {
context.read<CreateSceneBloc>().add(RemoveFromSelectedValueById(
code: widget.functions[widget.index].code));
}
}
}
if (widget.functionValue != null) {
setState(() {
groupValue = widget.functionValue;
@ -49,6 +50,7 @@ class _AlertDialogFunctionsOperationsBodyState
}
dynamic groupValue;
@override
Widget build(BuildContext context) {
return SingleChildScrollView(

View File

@ -10,7 +10,11 @@ import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
class CreateSceneSaveButton extends StatefulWidget {
const CreateSceneSaveButton({
super.key,
required this.sceneName,
required this.sceneId,
});
final String sceneName;
final String sceneId;
@override
State<CreateSceneSaveButton> createState() => _CreateSceneSaveButtonState();
@ -22,7 +26,8 @@ class _CreateSceneSaveButtonState extends State<CreateSceneSaveButton>
@override
void initState() {
sceneNameController = TextEditingController();
sceneNameController = TextEditingController(
text: widget.sceneName.isNotEmpty ? widget.sceneName : '');
super.initState();
}
@ -59,39 +64,58 @@ class _CreateSceneSaveButtonState extends State<CreateSceneSaveButton>
},
builder: (context, state) {
return DefaultButton(
onPressed: () {
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) {
onPressed: widget.sceneName.isNotEmpty
? () {
final tasks = context.read<CreateSceneBloc>().tasksList;
handleSaveButtonPress(context, sceneNameController, tasks);
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),
),
),
),
title: 'Scene Name',
onConfirm: () {
if (sceneNameController.text.isNotEmpty) {
final tasks = context.read<CreateSceneBloc>().tasksList;
handleSaveButtonPress(
context,
sceneNameController,
tasks,
updateScene: false,
sceneId: widget.sceneId,
);
}
},
);
},
customButtonStyle: ButtonStyle(
backgroundColor: WidgetStateProperty.all<Color>(
ColorsManager.primaryColorWithOpacity,
ColorsManager.primaryColor,
),
),
isLoading: state is CreateSceneLoading,

View File

@ -4,10 +4,10 @@ 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/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';
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';
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/text_widgets/body_medium.dart';
@ -15,16 +15,17 @@ import 'package:syncrow_app/generated/assets.dart';
import 'package:syncrow_app/utils/context_extension.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
class ThenAddedTasksContainer extends StatelessWidget {
class ThenAddedTasksContainer extends StatelessWidget
with SceneOperationsDataHelper, SceneLogicHelper {
ThenAddedTasksContainer({
super.key,
required this.taskList,
required this.taskItem,
this.sceneId,
this.index,
this.listOfSceneStaticFunction,
});
final SceneStaticFunction taskList;
final SceneStaticFunction taskItem;
String? sceneId;
List<SceneStaticFunction>? listOfSceneStaticFunction;
int? index;
@ -32,43 +33,31 @@ class ThenAddedTasksContainer extends StatelessWidget {
@override
Widget build(BuildContext context) {
String operationValue = '';
if (taskList.code.contains('countdown')) {
if (taskItem.code.contains('countdown')) {
final functionValue =
taskList.functionValue ?? taskList.operationalValues.first.value;
taskItem.functionValue ?? taskItem.operationalValues.first.value;
final duration =
Duration(seconds: int.tryParse(functionValue.toString()) ?? 0);
operationValue =
"${duration.inHours}h ${duration.inMinutes.remainder(60)}m ";
} else {
final functionValue =
taskList.functionValue ?? taskList.operationalValues.first.value;
taskItem.functionValue ?? taskItem.operationalValues.first.value;
operationValue = functionValue.toString();
}
return DefaultContainer(
onTap: () {
onTap: () async {
// List<SceneStaticFunction> functionOperation = [];
// if (sceneId == null) {
// functionOperation = getOperationsForOneFunction(
// taskItem: taskItem, deviceId: taskItem.deviceId);
// }
context.customAlertDialog(
alertBody: taskList.code == 'temp_set'
? AlertDialogTemperatureBody(
index: index!,
functions: listOfSceneStaticFunction ?? [],
functionValue: taskList.functionValue,
)
: (listOfSceneStaticFunction![index!]
.code
.contains('countdown') ||
listOfSceneStaticFunction![index!]
.code
.contains('presence_time'))
? AlertDialogCountdown(
durationValue:
listOfSceneStaticFunction![index!].functionValue,
functionValue: taskList.functionValue,
function: listOfSceneStaticFunction![index!],
)
: AlertDialogFunctionsOperationsBody(
index: index!,
functions: listOfSceneStaticFunction ?? [],
functionValue: taskList.functionValue),
alertBody: getTheCorrectDialogBody(
taskItem,
listOfSceneStaticFunction,
index,
),
title: listOfSceneStaticFunction![index!].operationName,
onConfirm: () {
// final selectedValue = context.read<CreateSceneBloc>().selectedValue;
@ -89,7 +78,7 @@ class ThenAddedTasksContainer extends StatelessWidget {
},
padding: EdgeInsets.zero,
child: Dismissible(
key: Key(taskList.uniqueCustomId.toString()),
key: Key(taskItem.uniqueCustomId.toString()),
background: Container(
padding: const EdgeInsets.only(right: 10),
alignment: AlignmentDirectional.centerEnd,
@ -110,14 +99,14 @@ class ThenAddedTasksContainer extends StatelessWidget {
),
direction: DismissDirection.endToStart,
onDismissed: (direction) {
String removeFunctionById = taskList.uniqueCustomId;
String removeFunctionById = taskItem.uniqueCustomId;
context
.read<CreateSceneBloc>()
.add(RemoveTaskByIdEvent(taskId: removeFunctionById));
String removeFunction =
"${taskList.operationName} with value ${taskList.operationalValues.first.value}";
"${taskItem.operationName} with value ${taskItem.operationalValues.first.value}";
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('$removeFunction removed')),
@ -125,10 +114,10 @@ class ThenAddedTasksContainer extends StatelessWidget {
},
child: SceneListTile(
padding: EdgeInsets.zero,
assetPath: taskList.icon,
assetPath: taskItem.icon,
iconsSize: 32,
titleWidget: BodyMedium(
text: taskList.deviceName,
text: taskItem.deviceName,
style: context.bodyMedium.copyWith(
fontWeight: FontWeight.bold,
),
@ -136,7 +125,7 @@ class ThenAddedTasksContainer extends StatelessWidget {
subtitleWidget: Row(
children: [
BodyMedium(
text: "${taskList.operationName}: ",
text: "${taskItem.operationName}: ",
fontColor: ColorsManager.secondaryTextColor,
fontWeight: FontWeight.normal,
),

View File

@ -50,70 +50,43 @@ class ThenDefaultContainer extends StatelessWidget {
padding: EdgeInsets.zero,
),
const LightDivider(),
sceneId.isNotEmpty
? BlocProvider(
create: (context) => CreateSceneBloc()
..add(FetchSceneTasksEvent(sceneId: sceneId)),
child: BlocBuilder<CreateSceneBloc, CreateSceneState>(
builder: (context, state) {
if (state is CreateSceneLoading) {
return const Center(child: LinearProgressIndicator());
}
if (state is AddSceneTask) {
final taskLists = state.tasksList;
if (taskLists.isNotEmpty) {
return ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: taskLists.length,
itemBuilder: (context, index) {
return ThenAddedTasksContainer(
taskList: taskLists[index],
index: index,
listOfSceneStaticFunction: taskLists,
sceneId: sceneId,
);
},
);
}
return const SizedBox();
}
return const SizedBox();
},
))
: BlocBuilder<CreateSceneBloc, CreateSceneState>(
builder: (context, state) {
if (state is AddSceneTask) {
final taskLists = state.tasksList;
if (taskLists.isNotEmpty) {
return ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: taskLists.length,
itemBuilder: (context, index) {
return ThenAddedTasksContainer(
taskList: taskLists[index],
);
},
);
}
return SceneListTile(
titleString: '+ Add Task',
textAlign: TextAlign.center,
onPressed: () => context.customBottomSheet(
child: const CustomBottomSheetWidget(),
),
BlocBuilder<CreateSceneBloc, CreateSceneState>(
builder: (context, state) {
if (state is CreateSceneLoading) {
return const Center(child: LinearProgressIndicator());
}
if (state is AddSceneTask) {
final taskLists = state.tasksList;
if (taskLists.isNotEmpty) {
return ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: taskLists.length,
reverse: true,
itemBuilder: (context, index) {
return ThenAddedTasksContainer(
taskItem: taskLists[index],
);
}
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(),
),
);
}
return SceneListTile(
titleString: '+ Add Task',
textAlign: TextAlign.center,
onPressed: () => context.customBottomSheet(
child: const CustomBottomSheetWidget(),
),
);
},
)
],
),
);

View File

@ -1,5 +1,6 @@
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/bloc/scene_bloc/scene_bloc.dart';
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart';
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
@ -35,6 +36,8 @@ class SceneItem extends StatelessWidget {
sceneName: scene.name,
),
);
BlocProvider.of<CreateSceneBloc>(context)
.add(FetchSceneTasksEvent(sceneId: scene.id));
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,