mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 01:56:19 +00:00
finished adding tasks and removing them , added error handling
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
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';
|
||||
|
||||
class AlertDialogCountdown extends StatefulWidget {
|
||||
const AlertDialogCountdown({super.key, required this.durationValue});
|
||||
@ -29,6 +30,9 @@ class _AlertDialogCountdownState extends State<AlertDialogCountdown> {
|
||||
setState(() {
|
||||
durationInSeconds = newDuration.inSeconds;
|
||||
});
|
||||
context
|
||||
.read<CreateSceneBloc>()
|
||||
.add(SelectedValueEvent(value: newDuration.inSeconds.toString()));
|
||||
},
|
||||
),
|
||||
);
|
||||
|
@ -1,4 +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/model/scene_static_function.dart';
|
||||
import 'package:syncrow_app/features/scene/widgets/scene_list_tile.dart';
|
||||
|
||||
@ -27,26 +29,38 @@ class _AlertDialogFunctionsOperationsBodyState
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
...widget.functions[widget.index].operationalValues.map(
|
||||
(operation) => SceneListTile(
|
||||
iconsSize: 25,
|
||||
minLeadingWidth: 15,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
assetPath: operation.icon,
|
||||
titleString: operation.value,
|
||||
textAlign: TextAlign.start,
|
||||
trailingWidget: Radio(
|
||||
value: operation.value,
|
||||
groupValue: groupValue,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
groupValue = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
groupValue = operation.value;
|
||||
});
|
||||
(operation) => BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
||||
builder: (context, state) {
|
||||
return SceneListTile(
|
||||
iconsSize: 25,
|
||||
minLeadingWidth: 15,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
assetPath: operation.icon,
|
||||
titleString: operation.value,
|
||||
textAlign: TextAlign.start,
|
||||
trailingWidget: Radio(
|
||||
value: operation.value,
|
||||
groupValue: (state is SelectedTaskValueState)
|
||||
? state.value
|
||||
: groupValue,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
groupValue = value;
|
||||
});
|
||||
context
|
||||
.read<CreateSceneBloc>()
|
||||
.add(SelectedValueEvent(value: value!));
|
||||
},
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
groupValue = operation.value;
|
||||
});
|
||||
context
|
||||
.read<CreateSceneBloc>()
|
||||
.add(SelectedValueEvent(value: groupValue!));
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
@ -1,5 +1,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/model/scene_static_function.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/title_medium.dart';
|
||||
@ -24,7 +26,7 @@ class AlertDialogTemperatureBody extends StatefulWidget {
|
||||
|
||||
class _AlertDialogTemperatureBodyState
|
||||
extends State<AlertDialogTemperatureBody> {
|
||||
double temperature = 16;
|
||||
int temperature = 24;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
@ -32,8 +34,13 @@ class _AlertDialogTemperatureBodyState
|
||||
leading: IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
temperature--;
|
||||
if (temperature > 20) {
|
||||
temperature--;
|
||||
}
|
||||
});
|
||||
context
|
||||
.read<CreateSceneBloc>()
|
||||
.add(SelectedValueEvent(value: temperature.toString()));
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.remove,
|
||||
@ -69,8 +76,13 @@ class _AlertDialogTemperatureBodyState
|
||||
trailing: IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
temperature++;
|
||||
if (temperature < 30) {
|
||||
temperature++;
|
||||
}
|
||||
});
|
||||
context
|
||||
.read<CreateSceneBloc>()
|
||||
.add(SelectedValueEvent(value: temperature.toString()));
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.add,
|
||||
|
@ -0,0 +1,99 @@
|
||||
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/model/scene_static_function.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';
|
||||
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 {
|
||||
const ThenAddedTasksContainer({
|
||||
super.key,
|
||||
required this.taskList,
|
||||
});
|
||||
|
||||
final SceneStaticFunction taskList;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String operationValue = '';
|
||||
if (taskList.code.contains('countdown')) {
|
||||
final duration = Duration(
|
||||
seconds:
|
||||
int.tryParse(taskList.operationalValues.first.value.toString()) ??
|
||||
0);
|
||||
operationValue =
|
||||
"${duration.inHours}h ${duration.inMinutes.remainder(60)}m ";
|
||||
} else {
|
||||
operationValue = taskList.operationalValues.first.value.toString();
|
||||
}
|
||||
return DefaultContainer(
|
||||
padding: EdgeInsets.zero,
|
||||
child: Dismissible(
|
||||
key: Key(taskList.uniqueCustomId.toString()),
|
||||
background: Container(
|
||||
padding: const EdgeInsets.only(right: 10),
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
decoration: const ShapeDecoration(
|
||||
color: Color(0xFFFF0000),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(20),
|
||||
bottomRight: Radius.circular(20),
|
||||
),
|
||||
),
|
||||
),
|
||||
child: SvgPicture.asset(
|
||||
Assets.assetsDeleteIcon,
|
||||
width: 20,
|
||||
height: 22,
|
||||
),
|
||||
),
|
||||
direction: DismissDirection.endToStart,
|
||||
onDismissed: (direction) {
|
||||
String removeFunctionById = taskList.uniqueCustomId;
|
||||
|
||||
context
|
||||
.read<CreateSceneBloc>()
|
||||
.add(RemoveTaskEvent(taskId: removeFunctionById));
|
||||
|
||||
String removeFunction =
|
||||
"${taskList.operationName} with value ${taskList.operationalValues.first.value}";
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('$removeFunction removed')),
|
||||
);
|
||||
},
|
||||
child: SceneListTile(
|
||||
padding: EdgeInsets.zero,
|
||||
assetPath: taskList.icon,
|
||||
iconsSize: 32,
|
||||
titleWidget: BodyMedium(
|
||||
text: taskList.deviceName,
|
||||
style: context.bodyMedium.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
subtitleWidget: Row(
|
||||
children: [
|
||||
BodyMedium(
|
||||
text: "${taskList.operationName}: ",
|
||||
fontColor: ColorsManager.secondaryTextColor,
|
||||
fontWeight: FontWeight.normal,
|
||||
),
|
||||
BodyMedium(
|
||||
text: operationValue,
|
||||
fontColor: ColorsManager.secondaryTextColor,
|
||||
fontWeight: FontWeight.normal,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -2,6 +2,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/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';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
@ -48,6 +49,28 @@ class ThenDefaultContainer extends StatelessWidget {
|
||||
const LightDivider(),
|
||||
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(),
|
||||
),
|
||||
);
|
||||
}
|
||||
return SceneListTile(
|
||||
titleString: '+ Add Task',
|
||||
textAlign: TextAlign.center,
|
||||
|
Reference in New Issue
Block a user