mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-14 17:25:47 +00:00
connect delete api
This commit is contained in:
@ -23,6 +23,7 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
on<TempHoldSceneTasksEvent>(_onTempHoldSceneTask);
|
||||
on<RemoveTempTaskByIdEvent>(_removeTempTaskById);
|
||||
on<RemoveFromSelectedValueById>(_removeFromSelectedValueById);
|
||||
on<DeleteSceneEvent>(_deleteScene);
|
||||
}
|
||||
|
||||
List<SceneStaticFunction> tasksList = [];
|
||||
@ -180,4 +181,21 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
|
||||
emit(const SelectedTaskValueState(value: null));
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _deleteScene(
|
||||
DeleteSceneEvent event, Emitter<CreateSceneState> emit) async {
|
||||
emit(DeleteSceneLoading());
|
||||
|
||||
try {
|
||||
final response = await SceneApi.deleteScene(
|
||||
sceneId: event.sceneId, unitUuid: event.unitUuid);
|
||||
if (response == true) {
|
||||
emit(const DeleteSceneSuccess(true));
|
||||
} else {
|
||||
emit(const DeleteSceneError(message: 'Something went wrong'));
|
||||
}
|
||||
} catch (e) {
|
||||
emit(const DeleteSceneError(message: 'Something went wrong'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -115,3 +115,15 @@ class FetchSceneTasksEvent extends CreateSceneEvent {
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class DeleteSceneEvent extends CreateSceneEvent {
|
||||
final String sceneId;
|
||||
final String unitUuid;
|
||||
const DeleteSceneEvent({
|
||||
required this.sceneId,
|
||||
required this.unitUuid,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object> get props => [sceneId, unitUuid];
|
||||
}
|
||||
|
@ -50,3 +50,21 @@ class CreateSceneWithTasks extends CreateSceneState {
|
||||
@override
|
||||
List<Object> get props => [success];
|
||||
}
|
||||
|
||||
class DeleteSceneSuccess extends CreateSceneState {
|
||||
final bool success;
|
||||
const DeleteSceneSuccess(this.success);
|
||||
|
||||
@override
|
||||
List<Object> get props => [success];
|
||||
}
|
||||
|
||||
class DeleteSceneError extends CreateSceneState {
|
||||
final String message;
|
||||
const DeleteSceneError({required this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
}
|
||||
|
||||
class DeleteSceneLoading extends CreateSceneState {}
|
||||
|
@ -49,7 +49,7 @@ class CreateSceneModel {
|
||||
|
||||
Map<String, dynamic> toMap([String? sceneId]) {
|
||||
return {
|
||||
if (sceneId != null) 'unitUuid': unitUuid,
|
||||
if (sceneId == null) 'unitUuid': unitUuid,
|
||||
'sceneName': sceneName,
|
||||
'decisionExpr': decisionExpr,
|
||||
'actions': actions.map((x) => x.toMap()).toList(),
|
||||
|
@ -1,11 +1,19 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/flutter_svg.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/scene_bloc/scene_bloc.dart';
|
||||
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart';
|
||||
import 'package:syncrow_app/features/scene/model/scene_settings_route_arguments.dart';
|
||||
import 'package:syncrow_app/features/scene/widgets/create_scene_save_button.dart';
|
||||
import 'package:syncrow_app/features/scene/widgets/if_then_containers/if_container.dart';
|
||||
import 'package:syncrow_app/features/scene/widgets/if_then_containers/then_container.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/default_scaffold.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/resource_manager/color_manager.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/strings_manager.dart';
|
||||
@ -26,6 +34,11 @@ class SceneTasksView extends StatelessWidget {
|
||||
SizedBox(
|
||||
width: 40,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
context.customBottomSheet(
|
||||
child: DeleteBottomSheetContent(sceneId: sceneSettings.sceneId),
|
||||
);
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
Assets.assetsIconsSettings,
|
||||
colorFilter: const ColorFilter.mode(
|
||||
@ -75,3 +88,54 @@ class SceneTasksView extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class DeleteBottomSheetContent extends StatelessWidget {
|
||||
const DeleteBottomSheetContent({super.key, required this.sceneId});
|
||||
|
||||
final String sceneId;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return DefaultContainer(
|
||||
height: context.height * 0.2,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
children: [
|
||||
BlocConsumer<CreateSceneBloc, CreateSceneState>(
|
||||
listener: (context, state) {
|
||||
if (state is DeleteSceneSuccess) {
|
||||
if (state.success) {
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(context);
|
||||
BlocProvider.of<SceneBloc>(context).add(
|
||||
LoadScenes(HomeCubit.getInstance().selectedSpace!.id!));
|
||||
}
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
return DefaultContainer(
|
||||
onTap: () {
|
||||
context.read<CreateSceneBloc>().add(DeleteSceneEvent(
|
||||
sceneId: sceneId,
|
||||
unitUuid:
|
||||
HomeCubit.getInstance().selectedSpace!.id!,
|
||||
));
|
||||
},
|
||||
child: SceneListTile(
|
||||
titleString: StringsManager.deleteScene,
|
||||
leadingWidget: (state is DeleteSceneLoading)
|
||||
? const SizedBox(
|
||||
height: 24,
|
||||
width: 24,
|
||||
child: CircularProgressIndicator())
|
||||
: SvgPicture.asset(
|
||||
Assets.assetsDeleteIcon,
|
||||
color: ColorsManager.red,
|
||||
),
|
||||
));
|
||||
},
|
||||
),
|
||||
],
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -18,11 +18,20 @@ class SceneView extends StatelessWidget {
|
||||
return BlocProvider(
|
||||
create: (BuildContext context) => SceneBloc()
|
||||
..add(LoadScenes(HomeCubit.getInstance().selectedSpace!.id!)),
|
||||
child: BlocListener<SceneBloc, SceneState>(
|
||||
child: BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
||||
builder: (context, state) {
|
||||
if (state is DeleteSceneSuccess) {
|
||||
if (state.success) {
|
||||
BlocProvider.of<SceneBloc>(context)
|
||||
.add(LoadScenes(HomeCubit.getInstance().selectedSpace!.id!));
|
||||
}
|
||||
}
|
||||
return BlocListener<SceneBloc, SceneState>(
|
||||
listener: (context, state) {
|
||||
if (state is SceneTriggerSuccess) {
|
||||
context.showCustomSnackbar(
|
||||
message: 'Scene ${state.sceneName} triggered successfully!');
|
||||
message:
|
||||
'Scene ${state.sceneName} triggered successfully!');
|
||||
}
|
||||
},
|
||||
child: HomeCubit.getInstance().spaces?.isEmpty ?? true
|
||||
@ -59,6 +68,8 @@ class SceneView extends StatelessWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ abstract class ApiEndpoints {
|
||||
|
||||
/// DELETE
|
||||
static const String deleteScene =
|
||||
'$baseUrl/scene/tap-to-run/{sceneUuid}/{sceneId}';
|
||||
'$baseUrl/scene/tap-to-run/{unitUuid}/{sceneId}';
|
||||
|
||||
//////////////////////Door Lock //////////////////////
|
||||
//online
|
||||
|
@ -76,7 +76,8 @@ class SceneApi {
|
||||
try {
|
||||
final response = await _httpService.put(
|
||||
path: ApiEndpoints.updateScene.replaceAll('{sceneId}', sceneId),
|
||||
body: createSceneModel.toJson(sceneId),
|
||||
body: createSceneModel
|
||||
.toJson(sceneId.isNotEmpty == true ? sceneId : null),
|
||||
expectedResponseModel: (json) {
|
||||
return json;
|
||||
},
|
||||
@ -88,4 +89,20 @@ class SceneApi {
|
||||
}
|
||||
|
||||
//deleteScene
|
||||
|
||||
static Future<bool> deleteScene(
|
||||
{required String unitUuid, required String sceneId}) async {
|
||||
try {
|
||||
final response = await _httpService.delete(
|
||||
path: ApiEndpoints.deleteScene
|
||||
.replaceAll('{sceneId}', sceneId)
|
||||
.replaceAll('{unitUuid}', unitUuid),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) => json['statusCode'] == 200,
|
||||
);
|
||||
return response;
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,8 @@ abstract class ColorsManager {
|
||||
static const Color switchOffColor = Color(0x7F8D99AE);
|
||||
static const Color primaryColor = Color(0xFF0030CB);
|
||||
static const Color secondaryTextColor = Color(0xFF848484);
|
||||
static Color primaryColorWithOpacity = const Color(0xFF023DFE).withOpacity(0.6);
|
||||
static Color primaryColorWithOpacity =
|
||||
const Color(0xFF023DFE).withOpacity(0.6);
|
||||
static const Color onPrimaryColor = Colors.white;
|
||||
static const Color secondaryColor = Color(0xFF023DFE);
|
||||
static const Color onSecondaryColor = Color(0xFF023DFE);
|
||||
@ -24,4 +25,5 @@ abstract class ColorsManager {
|
||||
static const Color blackColor = Color(0xFF000000);
|
||||
static const Color lightGreen = Color(0xFF00FF0A);
|
||||
static const Color grayColor = Color(0xFF999999);
|
||||
static const Color red = Colors.red;
|
||||
}
|
||||
|
@ -32,10 +32,12 @@ class StringsManager {
|
||||
static const String energizing = "Energizing";
|
||||
static const String createScene = 'Create Scene';
|
||||
static const String tapToRun = 'Launch: Tap - To - Run';
|
||||
static const String turnOffAllLights = 'Example: turn off all lights in the with one tap.';
|
||||
static const String turnOffAllLights =
|
||||
'Example: turn off all lights in the with one tap.';
|
||||
static const String whenDeviceStatusChanges = 'When device status changes';
|
||||
static const String whenUnusualActivityIsDetected =
|
||||
'Example: when an unusual activity is detected.';
|
||||
static const String functions = "Functions";
|
||||
static const String firstLaunch = "firstLaunch";
|
||||
static const String deleteScene = 'Delete Scene';
|
||||
}
|
||||
|
Reference in New Issue
Block a user