mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
integrate report and table view two sensors, use mock data for reports
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
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/all_devices/models/device_status.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/event.dart';
|
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/event.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/state.dart';
|
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/state.dart';
|
||||||
@ -14,6 +15,9 @@ class CeilingSensorBloc extends Bloc<CeilingSensorEvent, CeilingSensorState> {
|
|||||||
CeilingSensorBloc({required this.deviceId}) : super(CeilingInitialState()) {
|
CeilingSensorBloc({required this.deviceId}) : super(CeilingInitialState()) {
|
||||||
on<CeilingInitialEvent>(_fetchCeilingSensorStatus);
|
on<CeilingInitialEvent>(_fetchCeilingSensorStatus);
|
||||||
on<CeilingChangeValueEvent>(_changeValue);
|
on<CeilingChangeValueEvent>(_changeValue);
|
||||||
|
on<GetCeilingDeviceReportsEvent>(_getDeviceReports);
|
||||||
|
on<ShowCeilingDescriptionEvent>(_showDescription);
|
||||||
|
on<BackToCeilingGridViewEvent>(_backToGridView);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchCeilingSensorStatus(
|
void _fetchCeilingSensorStatus(
|
||||||
@ -49,7 +53,8 @@ class CeilingSensorBloc extends Bloc<CeilingSensorEvent, CeilingSensorState> {
|
|||||||
// } catch (_) {}
|
// } catch (_) {}
|
||||||
// }
|
// }
|
||||||
|
|
||||||
void _changeValue(CeilingChangeValueEvent event, Emitter<CeilingSensorState> emit) async {
|
void _changeValue(
|
||||||
|
CeilingChangeValueEvent event, Emitter<CeilingSensorState> emit) async {
|
||||||
emit(CeilingLoadingNewSate(ceilingSensorModel: deviceStatus));
|
emit(CeilingLoadingNewSate(ceilingSensorModel: deviceStatus));
|
||||||
if (event.code == 'sensitivity') {
|
if (event.code == 'sensitivity') {
|
||||||
deviceStatus.sensitivity = event.value;
|
deviceStatus.sensitivity = event.value;
|
||||||
@ -59,7 +64,8 @@ class CeilingSensorBloc extends Bloc<CeilingSensorEvent, CeilingSensorState> {
|
|||||||
deviceStatus.maxDistance = event.value;
|
deviceStatus.maxDistance = event.value;
|
||||||
}
|
}
|
||||||
emit(CeilingUpdateState(ceilingSensorModel: deviceStatus));
|
emit(CeilingUpdateState(ceilingSensorModel: deviceStatus));
|
||||||
await _runDeBouncer(deviceId: deviceId, code: event.code, value: event.value);
|
await _runDeBouncer(
|
||||||
|
deviceId: deviceId, code: event.code, value: event.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
_runDeBouncer({
|
_runDeBouncer({
|
||||||
@ -72,8 +78,8 @@ class CeilingSensorBloc extends Bloc<CeilingSensorEvent, CeilingSensorState> {
|
|||||||
}
|
}
|
||||||
_timer = Timer(const Duration(seconds: 1), () async {
|
_timer = Timer(const Duration(seconds: 1), () async {
|
||||||
try {
|
try {
|
||||||
final response =
|
final response = await DevicesManagementApi()
|
||||||
await DevicesManagementApi().deviceControl(deviceId, Status(code: code, value: value));
|
.deviceControl(deviceId, Status(code: code, value: value));
|
||||||
|
|
||||||
if (!response) {
|
if (!response) {
|
||||||
add(CeilingInitialEvent());
|
add(CeilingInitialEvent());
|
||||||
@ -84,4 +90,30 @@ class CeilingSensorBloc extends Bloc<CeilingSensorEvent, CeilingSensorState> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _getDeviceReports(GetCeilingDeviceReportsEvent event,
|
||||||
|
Emitter<CeilingSensorState> emit) async {
|
||||||
|
emit(CeilingReportsLoadingState());
|
||||||
|
|
||||||
|
try {
|
||||||
|
//await DevicesManagementApi.getDeviceReports(deviceId, event.code)
|
||||||
|
// .then((value) {
|
||||||
|
final fakeReport = FakeDeviceReport.generateFakeReport();
|
||||||
|
emit(CeilingReportsState(deviceReport: fakeReport));
|
||||||
|
// });
|
||||||
|
} catch (e) {
|
||||||
|
emit(CeilingReportsFailedState(error: e.toString()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _showDescription(
|
||||||
|
ShowCeilingDescriptionEvent event, Emitter<CeilingSensorState> emit) {
|
||||||
|
emit(ShowCeilingDescriptionState(description: event.description));
|
||||||
|
}
|
||||||
|
|
||||||
|
void _backToGridView(
|
||||||
|
BackToCeilingGridViewEvent event, Emitter<CeilingSensorState> emit) {
|
||||||
|
emit(CeilingUpdateState(ceilingSensorModel: deviceStatus));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,3 +17,25 @@ class CeilingChangeValueEvent extends CeilingSensorEvent {
|
|||||||
@override
|
@override
|
||||||
List<Object> get props => [value, code];
|
List<Object> get props => [value, code];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class GetCeilingDeviceReportsEvent extends CeilingSensorEvent {
|
||||||
|
final String code;
|
||||||
|
final String deviceUuid;
|
||||||
|
|
||||||
|
const GetCeilingDeviceReportsEvent(
|
||||||
|
{required this.code, required this.deviceUuid});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [code, deviceUuid];
|
||||||
|
}
|
||||||
|
|
||||||
|
class ShowCeilingDescriptionEvent extends CeilingSensorEvent {
|
||||||
|
final String description;
|
||||||
|
|
||||||
|
const ShowCeilingDescriptionEvent({required this.description});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [description];
|
||||||
|
}
|
||||||
|
|
||||||
|
class BackToCeilingGridViewEvent extends CeilingSensorEvent {}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_reports.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/model/ceiling_sensor_model.dart';
|
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/model/ceiling_sensor_model.dart';
|
||||||
|
|
||||||
class CeilingSensorState extends Equatable {
|
class CeilingSensorState extends Equatable {
|
||||||
@ -36,3 +37,32 @@ class CeilingFailedState extends CeilingSensorState {
|
|||||||
@override
|
@override
|
||||||
List<Object> get props => [error];
|
List<Object> get props => [error];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CeilingReportsState extends CeilingSensorState {
|
||||||
|
final DeviceReport deviceReport;
|
||||||
|
|
||||||
|
const CeilingReportsState({required this.deviceReport});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [deviceReport];
|
||||||
|
}
|
||||||
|
|
||||||
|
class CeilingReportsLoadingState extends CeilingSensorState {}
|
||||||
|
|
||||||
|
class CeilingReportsFailedState extends CeilingSensorState {
|
||||||
|
final String error;
|
||||||
|
|
||||||
|
const CeilingReportsFailedState({required this.error});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [error];
|
||||||
|
}
|
||||||
|
|
||||||
|
class ShowCeilingDescriptionState extends CeilingSensorState {
|
||||||
|
final String description;
|
||||||
|
|
||||||
|
const ShowCeilingDescriptionState({required this.description});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [description];
|
||||||
|
}
|
||||||
|
@ -4,10 +4,13 @@ import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_mo
|
|||||||
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/bloc.dart';
|
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/bloc.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/event.dart';
|
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/event.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/state.dart';
|
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/state.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/ceiling_sensor/model/ceiling_sensor_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_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_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_status.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/shared/sensors_widgets/presence_update_data.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/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||||
|
|
||||||
@ -29,6 +32,41 @@ class CeilingSensorControls extends StatelessWidget
|
|||||||
if (state is CeilingLoadingInitialState) {
|
if (state is CeilingLoadingInitialState) {
|
||||||
return const Center(child: CircularProgressIndicator());
|
return const Center(child: CircularProgressIndicator());
|
||||||
} else if (state is CeilingUpdateState) {
|
} else if (state is CeilingUpdateState) {
|
||||||
|
return _buildGridView(
|
||||||
|
context, state.ceilingSensorModel, isLarge, isMedium);
|
||||||
|
} else if (state is CeilingReportsState) {
|
||||||
|
return ReportsTable(
|
||||||
|
report: state.deviceReport,
|
||||||
|
onRowTap: (index) {
|
||||||
|
final entry = state.deviceReport.data![index];
|
||||||
|
context.read<CeilingSensorBloc>().add(
|
||||||
|
ShowCeilingDescriptionEvent(
|
||||||
|
description: entry['description']),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
onClose: () {
|
||||||
|
context.read<CeilingSensorBloc>().add(BackToCeilingGridViewEvent());
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else if (state is ShowCeilingDescriptionState) {
|
||||||
|
return DescriptionView(
|
||||||
|
description: state.description,
|
||||||
|
onClose: () {
|
||||||
|
context.read<CeilingSensorBloc>().add(BackToCeilingGridViewEvent());
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else if (state is CeilingReportsFailedState) {
|
||||||
|
final model = context.read<CeilingSensorBloc>().deviceStatus;
|
||||||
|
return _buildGridView(context, model, isLarge, isMedium);
|
||||||
|
}
|
||||||
|
return const Center(child: Text('Error fetching status'));
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildGridView(BuildContext context, CeilingSensorModel model,
|
||||||
|
bool isLarge, bool isMedium) {
|
||||||
return GridView(
|
return GridView(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 50),
|
padding: const EdgeInsets.symmetric(horizontal: 50),
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
@ -45,20 +83,20 @@ class CeilingSensorControls extends StatelessWidget
|
|||||||
),
|
),
|
||||||
children: [
|
children: [
|
||||||
PresenceState(
|
PresenceState(
|
||||||
value: state.ceilingSensorModel.presenceState,
|
value: model.presenceState,
|
||||||
),
|
),
|
||||||
PresenceDisplayValue(
|
PresenceDisplayValue(
|
||||||
value: state.ceilingSensorModel.sportsPara.toString(),
|
value: model.sportsPara.toString(),
|
||||||
postfix: '',
|
postfix: '',
|
||||||
description: 'Sports para',
|
description: 'Sports para',
|
||||||
),
|
),
|
||||||
PresenceDisplayValue(
|
PresenceDisplayValue(
|
||||||
value: state.ceilingSensorModel.presenceRange.toString(),
|
value: model.presenceRange.toString(),
|
||||||
postfix: 'm',
|
postfix: 'm',
|
||||||
description: 'Detection Range',
|
description: 'Detection Range',
|
||||||
),
|
),
|
||||||
PresenceUpdateData(
|
PresenceUpdateData(
|
||||||
value: state.ceilingSensorModel.sensitivity.toDouble(),
|
value: model.sensitivity.toDouble(),
|
||||||
title: 'Sensitivity:',
|
title: 'Sensitivity:',
|
||||||
minValue: 1,
|
minValue: 1,
|
||||||
maxValue: 5,
|
maxValue: 5,
|
||||||
@ -73,7 +111,7 @@ class CeilingSensorControls extends StatelessWidget
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
PresenceUpdateData(
|
PresenceUpdateData(
|
||||||
value: state.ceilingSensorModel.maxDistance.toDouble(),
|
value: model.maxDistance.toDouble(),
|
||||||
title: 'Maximum Distance:',
|
title: 'Maximum Distance:',
|
||||||
minValue: 0,
|
minValue: 0,
|
||||||
maxValue: 500,
|
maxValue: 500,
|
||||||
@ -88,8 +126,7 @@ class CeilingSensorControls extends StatelessWidget
|
|||||||
),
|
),
|
||||||
PresenceUpdateData(
|
PresenceUpdateData(
|
||||||
value:
|
value:
|
||||||
(state.ceilingSensorModel.noBodyTime.toDouble() / 3600)
|
(model.noBodyTime.toDouble() / 3600).roundToDouble(),
|
||||||
.roundToDouble(),
|
|
||||||
title: 'Nobody Time:',
|
title: 'Nobody Time:',
|
||||||
minValue: 0,
|
minValue: 0,
|
||||||
maxValue: 300000,
|
maxValue: 300000,
|
||||||
@ -102,26 +139,26 @@ class CeilingSensorControls extends StatelessWidget
|
|||||||
value: value,
|
value: value,
|
||||||
))),
|
))),
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () {},
|
onTap: () {
|
||||||
|
context.read<CeilingSensorBloc>().add(GetCeilingDeviceReportsEvent(
|
||||||
|
code: 'illuminance_record', deviceUuid: device.uuid!));
|
||||||
|
},
|
||||||
child: const PresenceStaticWidget(
|
child: const PresenceStaticWidget(
|
||||||
icon: Assets.illuminanceRecordIcon,
|
icon: Assets.illuminanceRecordIcon,
|
||||||
description: 'Presence Record',
|
description: 'Presence Record',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () {},
|
onTap: () {
|
||||||
|
context.read<CeilingSensorBloc>().add(GetCeilingDeviceReportsEvent(
|
||||||
|
code: 'presence_record', deviceUuid: device.uuid!));
|
||||||
|
},
|
||||||
child: const PresenceStaticWidget(
|
child: const PresenceStaticWidget(
|
||||||
icon: Assets.helpDescriptionIcon,
|
icon: Assets.presenceRecordIcon,
|
||||||
description: 'Help Description',
|
description: 'Presence Record',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
return const Center(child: Text('Error fetching status'));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,48 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class DescriptionView extends StatelessWidget {
|
||||||
|
final String description;
|
||||||
|
final VoidCallback onClose;
|
||||||
|
|
||||||
|
const DescriptionView({
|
||||||
|
super.key,
|
||||||
|
required this.description,
|
||||||
|
required this.onClose,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 50),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'Help Description',
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.bodyMedium!
|
||||||
|
.copyWith(color: Colors.grey),
|
||||||
|
),
|
||||||
|
GestureDetector(
|
||||||
|
onTap: onClose,
|
||||||
|
child: Text(
|
||||||
|
'Close',
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.bodyMedium!
|
||||||
|
.copyWith(color: Colors.grey),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
Text(description),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
72
lib/pages/device_managment/shared/table/report_table.dart
Normal file
72
lib/pages/device_managment/shared/table/report_table.dart
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_reports.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/shared/table/table_cell_widget.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/shared/table/table_header.dart';
|
||||||
|
|
||||||
|
class ReportsTable extends StatelessWidget {
|
||||||
|
final DeviceReport report;
|
||||||
|
final Function(int index) onRowTap;
|
||||||
|
final VoidCallback onClose;
|
||||||
|
|
||||||
|
const ReportsTable({
|
||||||
|
super.key,
|
||||||
|
required this.report,
|
||||||
|
required this.onRowTap,
|
||||||
|
required this.onClose,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Stack(
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(20.0),
|
||||||
|
child: Table(
|
||||||
|
border: TableBorder.all(color: Colors.grey.shade300, width: 1),
|
||||||
|
columnWidths: const {
|
||||||
|
0: FlexColumnWidth(),
|
||||||
|
1: FlexColumnWidth(),
|
||||||
|
2: FlexColumnWidth(),
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
TableRow(
|
||||||
|
decoration: BoxDecoration(color: Colors.grey.shade200),
|
||||||
|
children: const [
|
||||||
|
TableHeader(title: 'Date'),
|
||||||
|
TableHeader(title: 'Time'),
|
||||||
|
TableHeader(title: 'Status'),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
...report.data!.asMap().entries.map((entry) {
|
||||||
|
int index = entry.key;
|
||||||
|
var data = entry.value;
|
||||||
|
return TableRow(
|
||||||
|
children: [
|
||||||
|
TableCellWidget(value: data['date']),
|
||||||
|
TableCellWidget(value: data['time']),
|
||||||
|
TableCellWidget(
|
||||||
|
value: data['status'],
|
||||||
|
onTap: () => onRowTap(index),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Positioned(
|
||||||
|
top: 0,
|
||||||
|
right: 0,
|
||||||
|
child: IconButton(
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.close,
|
||||||
|
color: Colors.red,
|
||||||
|
size: 18,
|
||||||
|
),
|
||||||
|
onPressed: onClose,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class TableCellWidget extends StatelessWidget {
|
||||||
|
final String value;
|
||||||
|
final Function()? onTap;
|
||||||
|
|
||||||
|
const TableCellWidget({
|
||||||
|
super.key,
|
||||||
|
required this.value,
|
||||||
|
this.onTap,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: onTap,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Text(value),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
21
lib/pages/device_managment/shared/table/table_header.dart
Normal file
21
lib/pages/device_managment/shared/table/table_header.dart
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class TableHeader extends StatelessWidget {
|
||||||
|
final String title;
|
||||||
|
|
||||||
|
const TableHeader({
|
||||||
|
super.key,
|
||||||
|
required this.title,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Text(
|
||||||
|
title,
|
||||||
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,8 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_reports.dart';
|
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.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/bloc.dart';
|
import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/bloc.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/event.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';
|
import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/state.dart';
|
||||||
@ -33,9 +34,25 @@ class WallSensorControls extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
return _buildGridView(
|
return _buildGridView(
|
||||||
context, state.wallSensorModel, isLarge, isMedium);
|
context, state.wallSensorModel, isLarge, isMedium);
|
||||||
} else if (state is DeviceReportsState) {
|
} else if (state is DeviceReportsState) {
|
||||||
return _buildReportsTable(context, state.deviceReport);
|
return ReportsTable(
|
||||||
|
report: state.deviceReport,
|
||||||
|
onRowTap: (index) {
|
||||||
|
final entry = state.deviceReport.data![index];
|
||||||
|
context.read<WallSensorBloc>().add(
|
||||||
|
ShowDescriptionEvent(description: entry['description']),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
onClose: () {
|
||||||
|
context.read<WallSensorBloc>().add(BackToGridViewEvent());
|
||||||
|
},
|
||||||
|
);
|
||||||
} else if (state is WallSensorShowDescriptionState) {
|
} else if (state is WallSensorShowDescriptionState) {
|
||||||
return _buildDescriptionView(context, state.description);
|
return DescriptionView(
|
||||||
|
description: state.description,
|
||||||
|
onClose: () {
|
||||||
|
context.read<WallSensorBloc>().add(BackToGridViewEvent());
|
||||||
|
},
|
||||||
|
);
|
||||||
} else if (state is DeviceReportsFailedState) {
|
} else if (state is DeviceReportsFailedState) {
|
||||||
final model = context.read<WallSensorBloc>().deviceStatus;
|
final model = context.read<WallSensorBloc>().deviceStatus;
|
||||||
return _buildGridView(context, model, isLarge, isMedium);
|
return _buildGridView(context, model, isLarge, isMedium);
|
||||||
@ -159,119 +176,6 @@ class WallSensorControls extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildReportsTable(BuildContext context, DeviceReport report) {
|
|
||||||
return Stack(
|
|
||||||
children: [
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.all(20.0),
|
|
||||||
child: Table(
|
|
||||||
border: TableBorder.all(color: Colors.grey.shade300, width: 1),
|
|
||||||
columnWidths: const {
|
|
||||||
0: FlexColumnWidth(),
|
|
||||||
1: FlexColumnWidth(),
|
|
||||||
2: FlexColumnWidth(),
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
TableRow(
|
|
||||||
decoration: BoxDecoration(color: Colors.grey.shade200),
|
|
||||||
children: [
|
|
||||||
_buildTableHeader('Date'),
|
|
||||||
_buildTableHeader('Time'),
|
|
||||||
_buildTableHeader('Status'),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
...report.data!.map((entry) {
|
|
||||||
return TableRow(
|
|
||||||
children: [
|
|
||||||
_buildTableCell(entry['date']),
|
|
||||||
_buildTableCell(entry['time']),
|
|
||||||
GestureDetector(
|
|
||||||
onTap: () {
|
|
||||||
context.read<WallSensorBloc>().add(
|
|
||||||
ShowDescriptionEvent(
|
|
||||||
description: entry['description']),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
child: _buildTableCell(entry['status']),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}).toList(),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Positioned(
|
|
||||||
top: 0,
|
|
||||||
right: 0,
|
|
||||||
child: IconButton(
|
|
||||||
icon: const Icon(
|
|
||||||
Icons.close,
|
|
||||||
color: Colors.red,
|
|
||||||
size: 18,
|
|
||||||
),
|
|
||||||
onPressed: () {
|
|
||||||
context.read<WallSensorBloc>().add(BackToGridViewEvent());
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildDescriptionView(BuildContext context, String description) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 50),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
'Help Description',
|
|
||||||
style: Theme.of(context)
|
|
||||||
.textTheme
|
|
||||||
.bodyMedium!
|
|
||||||
.copyWith(color: Colors.grey),
|
|
||||||
),
|
|
||||||
GestureDetector(
|
|
||||||
onTap: () {
|
|
||||||
context.read<WallSensorBloc>().add(BackToGridViewEvent());
|
|
||||||
},
|
|
||||||
child: Text(
|
|
||||||
'Close',
|
|
||||||
style: Theme.of(context)
|
|
||||||
.textTheme
|
|
||||||
.bodyMedium!
|
|
||||||
.copyWith(color: Colors.grey),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 10),
|
|
||||||
Text(description),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildTableHeader(String title) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
|
||||||
child: Text(
|
|
||||||
title,
|
|
||||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildTableCell(String value) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
|
||||||
child: Text(value),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// BlocBuilder<WallSensorBloc, WallSensorState>(
|
// BlocBuilder<WallSensorBloc, WallSensorState>(
|
||||||
// builder: (context, state) {
|
// builder: (context, state) {
|
||||||
// if (state is WallSensorLoadingInitialState) {
|
// if (state is WallSensorLoadingInitialState) {
|
||||||
|
Reference in New Issue
Block a user