mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
@ -55,8 +55,7 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
|
||||
) async {
|
||||
emit(WallSensorLoadingInitialState());
|
||||
try {
|
||||
final response =
|
||||
await DevicesManagementApi().getBatchStatus(event.devicesIds);
|
||||
final response = await DevicesManagementApi().getBatchStatus(event.devicesIds);
|
||||
deviceStatus = WallSensorModel.fromJson(response.status);
|
||||
emit(WallSensorUpdateState(wallSensorModel: deviceStatus));
|
||||
} catch (e) {
|
||||
@ -69,9 +68,9 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
|
||||
final ref = FirebaseDatabase.instance.ref('device-status/$deviceId');
|
||||
|
||||
ref.onValue.listen((event) {
|
||||
final eventsMap = event.snapshot.value! as Map<dynamic, dynamic>;
|
||||
final eventsMap = event.snapshot.value as Map<dynamic, dynamic>;
|
||||
|
||||
final statusList = <Status>[];
|
||||
List<Status> statusList = [];
|
||||
eventsMap['status'].forEach((element) {
|
||||
statusList.add(
|
||||
Status(code: element['code'], value: element['value']),
|
||||
|
@ -23,46 +23,46 @@ class WallSensorModel {
|
||||
required this.noBodyTime});
|
||||
|
||||
factory WallSensorModel.fromJson(List<Status> jsonList) {
|
||||
late String presenceState;
|
||||
late int farDetection;
|
||||
late int presenceTime;
|
||||
late int motionSensitivity;
|
||||
late int motionlessSensitivity;
|
||||
late int currentDistance;
|
||||
late int illuminance;
|
||||
late bool indicator;
|
||||
late int noBodyTime;
|
||||
late String _presenceState;
|
||||
late int _farDetection;
|
||||
late int _presenceTime;
|
||||
late int _motionSensitivity;
|
||||
late int _motionlessSensitivity;
|
||||
late int _currentDistance;
|
||||
late int _illuminance;
|
||||
late bool _indicator;
|
||||
late int _noBodyTime;
|
||||
|
||||
for (var i = 0; i < jsonList.length; i++) {
|
||||
for (int i = 0; i < jsonList.length; i++) {
|
||||
if (jsonList[i].code == 'presence_state') {
|
||||
presenceState = jsonList[i].value ?? 'none';
|
||||
_presenceState = jsonList[i].value ?? 'none';
|
||||
} else if (jsonList[i].code == 'far_detection') {
|
||||
farDetection = jsonList[i].value ?? 0;
|
||||
_farDetection = jsonList[i].value ?? 0;
|
||||
} else if (jsonList[i].code == 'presence_time') {
|
||||
presenceTime = jsonList[i].value ?? 0;
|
||||
_presenceTime = jsonList[i].value ?? 0;
|
||||
} else if (jsonList[i].code == 'motion_sensitivity_value') {
|
||||
motionSensitivity = jsonList[i].value ?? 0;
|
||||
_motionSensitivity = jsonList[i].value ?? 0;
|
||||
} else if (jsonList[i].code == 'motionless_sensitivity') {
|
||||
motionlessSensitivity = jsonList[i].value ?? 0;
|
||||
_motionlessSensitivity = jsonList[i].value ?? 0;
|
||||
} else if (jsonList[i].code == 'dis_current') {
|
||||
currentDistance = jsonList[i].value ?? 0;
|
||||
_currentDistance = jsonList[i].value ?? 0;
|
||||
} else if (jsonList[i].code == 'illuminance_value') {
|
||||
illuminance = jsonList[i].value ?? 0;
|
||||
_illuminance = jsonList[i].value ?? 0;
|
||||
} else if (jsonList[i].code == 'indicator') {
|
||||
indicator = jsonList[i].value ?? false;
|
||||
_indicator = jsonList[i].value ?? false;
|
||||
} else if (jsonList[i].code == 'no_one_time') {
|
||||
noBodyTime = jsonList[i].value ?? 0;
|
||||
_noBodyTime = jsonList[i].value ?? 0;
|
||||
}
|
||||
}
|
||||
return WallSensorModel(
|
||||
presenceState: presenceState,
|
||||
farDetection: farDetection,
|
||||
presenceTime: presenceTime,
|
||||
motionSensitivity: motionSensitivity,
|
||||
motionlessSensitivity: motionlessSensitivity,
|
||||
currentDistance: currentDistance,
|
||||
illuminance: illuminance,
|
||||
indicator: indicator,
|
||||
noBodyTime: noBodyTime);
|
||||
presenceState: _presenceState,
|
||||
farDetection: _farDetection,
|
||||
presenceTime: _presenceTime,
|
||||
motionSensitivity: _motionSensitivity,
|
||||
motionlessSensitivity: _motionlessSensitivity,
|
||||
currentDistance: _currentDistance,
|
||||
illuminance: _illuminance,
|
||||
indicator: _indicator,
|
||||
noBodyTime: _noBodyTime);
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,7 @@ import 'package:syncrow_web/pages/device_managment/wall_sensor/factories/wall_se
|
||||
import 'package:syncrow_web/pages/device_managment/wall_sensor/model/wall_sensor_model.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
|
||||
class WallSensorBatchControlView extends StatelessWidget
|
||||
with HelperResponsiveLayout {
|
||||
class WallSensorBatchControlView extends StatelessWidget with HelperResponsiveLayout {
|
||||
const WallSensorBatchControlView({super.key, required this.devicesIds});
|
||||
|
||||
final List<String> devicesIds;
|
||||
@ -23,21 +22,17 @@ class WallSensorBatchControlView extends StatelessWidget
|
||||
final isLarge = isLargeScreenSize(context);
|
||||
final isMedium = isMediumScreenSize(context);
|
||||
return BlocProvider(
|
||||
create: (context) =>
|
||||
WallSensorBlocFactory.create(deviceId: devicesIds.first)
|
||||
..add(WallSensorFetchBatchStatusEvent(devicesIds)),
|
||||
create: (context) => WallSensorBlocFactory.create(deviceId: devicesIds.first)
|
||||
..add(WallSensorFetchBatchStatusEvent(devicesIds)),
|
||||
child: BlocBuilder<WallSensorBloc, WallSensorState>(
|
||||
builder: (context, state) {
|
||||
if (state is WallSensorLoadingInitialState ||
|
||||
state is DeviceReportsLoadingState) {
|
||||
if (state is WallSensorLoadingInitialState || state is DeviceReportsLoadingState) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (state is WallSensorUpdateState) {
|
||||
return _buildGridView(context, state.wallSensorModel, isExtraLarge,
|
||||
isLarge, isMedium);
|
||||
return _buildGridView(context, state.wallSensorModel, isExtraLarge, isLarge, isMedium);
|
||||
} else if (state is DeviceReportsFailedState) {
|
||||
final model = context.read<WallSensorBloc>().deviceStatus;
|
||||
return _buildGridView(
|
||||
context, model, isExtraLarge, isLarge, isMedium);
|
||||
return _buildGridView(context, model, isExtraLarge, isLarge, isMedium);
|
||||
}
|
||||
return const Center(child: Text('Error fetching status'));
|
||||
},
|
||||
@ -45,8 +40,8 @@ class WallSensorBatchControlView extends StatelessWidget
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildGridView(BuildContext context, WallSensorModel model,
|
||||
bool isExtraLarge, bool isLarge, bool isMedium) {
|
||||
Widget _buildGridView(
|
||||
BuildContext context, WallSensorModel model, bool isExtraLarge, bool isLarge, bool isMedium) {
|
||||
return GridView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 50, vertical: 20),
|
||||
shrinkWrap: true,
|
||||
@ -99,12 +94,11 @@ class WallSensorBatchControlView extends StatelessWidget
|
||||
maxValue: 10000,
|
||||
steps: 1,
|
||||
description: 'sec',
|
||||
action: (int value) =>
|
||||
context.read<WallSensorBloc>().add(WallSensorBatchControlEvent(
|
||||
deviceIds: devicesIds,
|
||||
code: 'no_one_time',
|
||||
value: value,
|
||||
))),
|
||||
action: (int value) => context.read<WallSensorBloc>().add(WallSensorBatchControlEvent(
|
||||
deviceIds: devicesIds,
|
||||
code: 'no_one_time',
|
||||
value: value,
|
||||
))),
|
||||
PresenceUpdateData(
|
||||
value: model.farDetection.toDouble(),
|
||||
title: 'Far Detection:',
|
||||
|
@ -1,22 +1,21 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/shared/sensors_widgets/presence_display_data.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/shared/sensors_widgets/presence_static_widget.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/shared/sensors_widgets/presence_status.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/shared/sensors_widgets/presence_update_data.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/shared/table/description_view.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/shared/table/report_table.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/wall_bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/wall_event.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/wall_state.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/shared/sensors_widgets/presence_display_data.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/shared/sensors_widgets/presence_static_widget.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/shared/sensors_widgets/presence_status.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/shared/sensors_widgets/presence_update_data.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/wall_sensor/factories/wall_sensor_bloc_factory.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/wall_sensor/model/wall_sensor_model.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
|
||||
class WallSensorControlsView extends StatelessWidget
|
||||
with HelperResponsiveLayout {
|
||||
class WallSensorControlsView extends StatelessWidget with HelperResponsiveLayout {
|
||||
const WallSensorControlsView({super.key, required this.device});
|
||||
|
||||
final AllDevicesModel device;
|
||||
@ -27,23 +26,19 @@ class WallSensorControlsView extends StatelessWidget
|
||||
final isLarge = isLargeScreenSize(context);
|
||||
final isMedium = isMediumScreenSize(context);
|
||||
return BlocProvider(
|
||||
create: (context) => WallSensorBlocFactory.create(deviceId: device.uuid!)
|
||||
..add(WallSensorFetchStatusEvent()),
|
||||
create: (context) =>
|
||||
WallSensorBlocFactory.create(deviceId: device.uuid!)..add(WallSensorFetchStatusEvent()),
|
||||
child: BlocBuilder<WallSensorBloc, WallSensorState>(
|
||||
builder: (context, state) {
|
||||
if (state is WallSensorLoadingInitialState ||
|
||||
state is DeviceReportsLoadingState) {
|
||||
if (state is WallSensorLoadingInitialState || state is DeviceReportsLoadingState) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (state is WallSensorUpdateState) {
|
||||
return _buildGridView(context, state.wallSensorModel, isExtraLarge,
|
||||
isLarge, isMedium);
|
||||
return _buildGridView(context, state.wallSensorModel, isExtraLarge, isLarge, isMedium);
|
||||
} else if (state is DeviceReportsState) {
|
||||
return ReportsTable(
|
||||
report: state.deviceReport,
|
||||
thirdColumnTitle:
|
||||
state.code == 'illuminance_value' ? 'Value' : 'Status',
|
||||
thirdColumnDescription:
|
||||
state.code == 'illuminance_value' ? 'Lux' : null,
|
||||
thirdColumnTitle: state.code == 'illuminance_value' ? "Value" : 'Status',
|
||||
thirdColumnDescription: state.code == 'illuminance_value' ? "Lux" : null,
|
||||
onRowTap: (index) {},
|
||||
onClose: () {
|
||||
context.read<WallSensorBloc>().add(BackToGridViewEvent());
|
||||
@ -58,8 +53,7 @@ class WallSensorControlsView extends StatelessWidget
|
||||
);
|
||||
} else if (state is DeviceReportsFailedState) {
|
||||
final model = context.read<WallSensorBloc>().deviceStatus;
|
||||
return _buildGridView(
|
||||
context, model, isExtraLarge, isLarge, isMedium);
|
||||
return _buildGridView(context, model, isExtraLarge, isLarge, isMedium);
|
||||
}
|
||||
return const Center(child: Text('Error fetching status'));
|
||||
},
|
||||
@ -67,8 +61,8 @@ class WallSensorControlsView extends StatelessWidget
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildGridView(BuildContext context, WallSensorModel model,
|
||||
bool isExtraLarge, bool isLarge, bool isMedium) {
|
||||
Widget _buildGridView(
|
||||
BuildContext context, WallSensorModel model, bool isExtraLarge, bool isLarge, bool isMedium) {
|
||||
return GridView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 50),
|
||||
shrinkWrap: true,
|
||||
@ -137,11 +131,10 @@ class WallSensorControlsView extends StatelessWidget
|
||||
maxValue: 10000,
|
||||
steps: 1,
|
||||
description: 'sec',
|
||||
action: (int value) =>
|
||||
context.read<WallSensorBloc>().add(WallSensorChangeValueEvent(
|
||||
code: 'no_one_time',
|
||||
value: value,
|
||||
))),
|
||||
action: (int value) => context.read<WallSensorBloc>().add(WallSensorChangeValueEvent(
|
||||
code: 'no_one_time',
|
||||
value: value,
|
||||
))),
|
||||
PresenceUpdateData(
|
||||
value: model.farDetection.toDouble(),
|
||||
title: 'Far Detection:',
|
||||
@ -158,8 +151,9 @@ class WallSensorControlsView extends StatelessWidget
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
context.read<WallSensorBloc>().add(GetDeviceReportsEvent(
|
||||
code: 'illuminance_value', deviceUuid: device.uuid!));
|
||||
context
|
||||
.read<WallSensorBloc>()
|
||||
.add(GetDeviceReportsEvent(code: 'illuminance_value', deviceUuid: device.uuid!));
|
||||
},
|
||||
child: const PresenceStaticWidget(
|
||||
icon: Assets.illuminanceRecordIcon,
|
||||
@ -168,8 +162,9 @@ class WallSensorControlsView extends StatelessWidget
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
context.read<WallSensorBloc>().add(GetDeviceReportsEvent(
|
||||
code: 'presence_state', deviceUuid: device.uuid!));
|
||||
context
|
||||
.read<WallSensorBloc>()
|
||||
.add(GetDeviceReportsEvent(code: 'presence_state', deviceUuid: device.uuid!));
|
||||
},
|
||||
child: const PresenceStaticWidget(
|
||||
icon: Assets.presenceRecordIcon,
|
||||
|
Reference in New Issue
Block a user