Refactor FactoryResetModel and MainDoorSensorBatchView

- Refactor FactoryResetModel to include 'operationType' in toJson and toMap methods.
- Refactor MainDoorSensorBatchView to use BlocProvider and Builder for better state management.
This commit is contained in:
mohammad
2025-04-16 15:06:50 +03:00
parent e0be44a507
commit 72ae3b1727
3 changed files with 29 additions and 30 deletions

View File

@ -19,6 +19,7 @@ class FactoryResetModel {
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
return { return {
'devicesUuid': devicesUuid, 'devicesUuid': devicesUuid,
'operationType': operationType,
}; };
} }
@ -33,6 +34,7 @@ class FactoryResetModel {
Map<String, dynamic> toMap() { Map<String, dynamic> toMap() {
return { return {
'devicesUuid': devicesUuid, 'devicesUuid': devicesUuid,
'operationType': operationType,
}; };
} }
@ -56,3 +58,4 @@ class FactoryResetModel {
@override @override
int get hashCode => devicesUuid.hashCode; int get hashCode => devicesUuid.hashCode;
} }

View File

@ -4,7 +4,6 @@ import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_re
import 'package:syncrow_web/pages/device_managment/main_door_sensor/bloc/main_door_sensor_bloc.dart'; import 'package:syncrow_web/pages/device_managment/main_door_sensor/bloc/main_door_sensor_bloc.dart';
import 'package:syncrow_web/pages/device_managment/main_door_sensor/bloc/main_door_sensor_event.dart'; import 'package:syncrow_web/pages/device_managment/main_door_sensor/bloc/main_door_sensor_event.dart';
import 'package:syncrow_web/pages/device_managment/shared/batch_control/factory_reset.dart'; import 'package:syncrow_web/pages/device_managment/shared/batch_control/factory_reset.dart';
// import 'package:syncrow_web/pages/device_managment/shared/batch_control/firmware_update.dart';
class MainDoorSensorBatchView extends StatelessWidget { class MainDoorSensorBatchView extends StatelessWidget {
const MainDoorSensorBatchView({super.key, required this.devicesIds}); const MainDoorSensorBatchView({super.key, required this.devicesIds});
@ -13,35 +12,31 @@ class MainDoorSensorBatchView extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Row( return BlocProvider(
mainAxisAlignment: MainAxisAlignment.center, create: (context) => MainDoorSensorBloc(),
children: [ child: Builder(
// SizedBox( builder: (innerContext) {
// width: 170, return Row(
// height: 140, mainAxisAlignment: MainAxisAlignment.center,
// child: FirmwareUpdateWidget( children: [
// deviceId: devicesIds.first, SizedBox(
// version: 12, width: 170,
// ), height: 140,
// ), child: FactoryResetWidget(
// const SizedBox( callFactoryReset: () {
// width: 12, BlocProvider.of<MainDoorSensorBloc>(innerContext).add(
// ), MainDoorSensorFactoryReset(
SizedBox( deviceId: devicesIds.first,
width: 170, factoryReset: FactoryResetModel(devicesUuid: devicesIds),
height: 140, ),
child: FactoryResetWidget( );
callFactoryReset: () { },
BlocProvider.of<MainDoorSensorBloc>(context).add(
MainDoorSensorFactoryReset(
deviceId: devicesIds.first,
factoryReset: FactoryResetModel(devicesUuid: devicesIds),
), ),
); ),
}, ],
), );
), },
], ),
); );
} }
} }

View File

@ -321,13 +321,14 @@ class DevicesManagementApi {
Future<bool> factoryReset(FactoryResetModel factoryReset, String uuid) async { Future<bool> factoryReset(FactoryResetModel factoryReset, String uuid) async {
try { try {
final response = await HTTPService().post( final response = await HTTPService().post(
path: ApiEndpoints.factoryReset.replaceAll('{deviceUuid}', uuid), path: ApiEndpoints.factoryReset,
body: factoryReset.toMap(), body: factoryReset.toMap(),
showServerMessage: true, showServerMessage: true,
expectedResponseModel: (json) { expectedResponseModel: (json) {
return json['success'] ?? false; return json['success'] ?? false;
}, },
); );
return response; return response;
} catch (e) { } catch (e) {
debugPrint('Error fetching $e'); debugPrint('Error fetching $e');