mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
102 lines
3.4 KiB
Dart
102 lines
3.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:intl/intl.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';
|
|
|
|
// ignore: must_be_immutable
|
|
class ReportsTable extends StatelessWidget {
|
|
final DeviceReport report;
|
|
final String? thirdColumnTitle;
|
|
final String? thirdColumnDescription;
|
|
final Function(int index) onRowTap;
|
|
final VoidCallback onClose;
|
|
bool? hideValueShowDescription;
|
|
bool? mainDoorSensor;
|
|
|
|
ReportsTable({
|
|
super.key,
|
|
required this.report,
|
|
required this.onRowTap,
|
|
required this.onClose,
|
|
this.thirdColumnTitle,
|
|
this.thirdColumnDescription,
|
|
this.hideValueShowDescription,
|
|
this.mainDoorSensor,
|
|
});
|
|
|
|
@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'),
|
|
const TableHeader(title: 'Time'),
|
|
TableHeader(title: thirdColumnTitle ?? 'Status'),
|
|
],
|
|
),
|
|
if (report.data != null)
|
|
...report.data!.asMap().entries.map((entry) {
|
|
int index = entry.key;
|
|
DeviceEvent data = entry.value;
|
|
|
|
// Parse eventTime into Date and Time
|
|
DateTime eventDateTime =
|
|
DateTime.fromMillisecondsSinceEpoch(data.eventTime!);
|
|
String date = DateFormat('dd/MM/yyyy').format(eventDateTime);
|
|
String time = DateFormat('HH:mm').format(eventDateTime);
|
|
|
|
return TableRow(
|
|
children: [
|
|
TableCellWidget(value: date),
|
|
TableCellWidget(value: time),
|
|
hideValueShowDescription == true
|
|
? TableCellWidget(
|
|
value: (mainDoorSensor != null &&
|
|
mainDoorSensor == true)
|
|
? data.value == 'true'
|
|
? 'Open'
|
|
: 'Close'
|
|
: thirdColumnDescription ?? '',
|
|
onTap: () => onRowTap(index),
|
|
)
|
|
: TableCellWidget(
|
|
value:
|
|
'${data.value!} ${thirdColumnDescription ?? ''}',
|
|
onTap: () => onRowTap(index),
|
|
),
|
|
],
|
|
);
|
|
}),
|
|
],
|
|
),
|
|
),
|
|
Positioned(
|
|
top: 0,
|
|
right: 0,
|
|
child: IconButton(
|
|
icon: const Icon(
|
|
Icons.close,
|
|
color: Colors.red,
|
|
size: 18,
|
|
),
|
|
onPressed: onClose,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|