connect generate reports model and api to view

This commit is contained in:
ashrafzarkanisala
2024-08-27 20:34:41 +03:00
parent 5daf7228af
commit bd99049fe4
8 changed files with 89 additions and 71 deletions

View File

@ -1,6 +1,5 @@
import 'dart:async';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/device_managment/all_devices/helper/fake_report_data.dart';
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/event.dart';
import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/state.dart';
@ -98,11 +97,10 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
emit(DeviceReportsLoadingState());
try {
//await DevicesManagementApi.getDeviceReports(deviceId, event.code)
// .then((value) {
final fakeReport = FakeDeviceReport.generateFakeReport();
emit(DeviceReportsState(deviceReport: fakeReport));
// });
await DevicesManagementApi.getDeviceReports(deviceId, event.code)
.then((value) {
emit(DeviceReportsState(deviceReport: value));
});
} catch (e) {
emit(DeviceReportsFailedState(error: e.toString()));
return;

View File

@ -28,7 +28,8 @@ class WallSensorControls extends StatelessWidget with HelperResponsiveLayout {
WallSensorBloc(deviceId: device.uuid!)..add(WallSensorInitialEvent()),
child: BlocBuilder<WallSensorBloc, WallSensorState>(
builder: (context, state) {
if (state is WallSensorLoadingInitialState) {
if (state is WallSensorLoadingInitialState ||
state is DeviceReportsLoadingState) {
return const Center(child: CircularProgressIndicator());
} else if (state is WallSensorUpdateState) {
return _buildGridView(
@ -36,12 +37,7 @@ class WallSensorControls extends StatelessWidget with HelperResponsiveLayout {
} else if (state is DeviceReportsState) {
return ReportsTable(
report: state.deviceReport,
onRowTap: (index) {
final entry = state.deviceReport.data![index];
context.read<WallSensorBloc>().add(
ShowDescriptionEvent(description: entry['description']),
);
},
onRowTap: (index) {},
onClose: () {
context.read<WallSensorBloc>().add(BackToGridViewEvent());
},
@ -155,7 +151,7 @@ class WallSensorControls extends StatelessWidget with HelperResponsiveLayout {
GestureDetector(
onTap: () {
context.read<WallSensorBloc>().add(GetDeviceReportsEvent(
code: 'illuminance_record', deviceUuid: device.uuid!));
code: 'illuminance_value', deviceUuid: device.uuid!));
},
child: const PresenceStaticWidget(
icon: Assets.illuminanceRecordIcon,
@ -165,7 +161,7 @@ class WallSensorControls extends StatelessWidget with HelperResponsiveLayout {
GestureDetector(
onTap: () {
context.read<WallSensorBloc>().add(GetDeviceReportsEvent(
code: 'presence_record', deviceUuid: device.uuid!));
code: 'presence_state', deviceUuid: device.uuid!));
},
child: const PresenceStaticWidget(
icon: Assets.presenceRecordIcon,