142 lines
4.7 KiB
Dart
142 lines
4.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:mobile_monitoring/core/constants/constants.dart';
|
|
|
|
class MonitoringRecapTable extends StatelessWidget {
|
|
final List<Map<String, dynamic>> data;
|
|
final DateTime? startDate;
|
|
|
|
const MonitoringRecapTable({
|
|
super.key,
|
|
required this.data,
|
|
this.startDate,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// Cek apakah ada data
|
|
if (data.isEmpty) {
|
|
return Center(
|
|
child: SizedBox(
|
|
width: 320,
|
|
child: Card(
|
|
elevation: 2,
|
|
color: AppColors.white,
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(24.0),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(Icons.agriculture, color: AppColors.primary, size: 50),
|
|
const SizedBox(height: 16),
|
|
const Text(
|
|
AppStrings.startPlantingFirst,
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
|
),
|
|
const SizedBox(height: 8),
|
|
const Text(
|
|
'Rekap monitoring akan muncul setelah Anda memulai monitoring',
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(fontSize: 12, color: Colors.grey),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
return Center(
|
|
child: SizedBox(
|
|
width: 320,
|
|
child: Card(
|
|
elevation: 2,
|
|
color: AppColors.white,
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(12.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Text(
|
|
'Rekap Monitoring 7 Hari Terakhir',
|
|
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16, color: AppColors.black),
|
|
),
|
|
const SizedBox(height: 8),
|
|
SingleChildScrollView(
|
|
scrollDirection: Axis.horizontal,
|
|
child: Container(
|
|
constraints: const BoxConstraints(minWidth: 500),
|
|
child: Table(
|
|
columnWidths: const {
|
|
0: FlexColumnWidth(1.2),
|
|
1: FlexColumnWidth(1.1),
|
|
2: FlexColumnWidth(1.1),
|
|
3: FlexColumnWidth(1.1),
|
|
},
|
|
border: TableBorder(horizontalInside: BorderSide(color: AppColors.borderLight, width: 1)),
|
|
children: [
|
|
TableRow(
|
|
decoration: const BoxDecoration(color: AppColors.lightGray),
|
|
children: [
|
|
_headerCell('Hari'),
|
|
_headerCell('Pagi'),
|
|
_headerCell('Sore'),
|
|
_headerCell('Malam'),
|
|
],
|
|
),
|
|
...data.map((row) => TableRow(
|
|
children: [
|
|
_bodyCell(row['day'], isBold: true),
|
|
_bodyCell(row['morning']),
|
|
_bodyCell(row['afternoon']),
|
|
_bodyCell(row['night']),
|
|
],
|
|
))
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
// Widget untuk header cell
|
|
static Widget _headerCell(String text) {
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 8),
|
|
alignment: Alignment.center,
|
|
child: Text(
|
|
text,
|
|
style: const TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
color: AppColors.textPrimary,
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
// Widget untuk body cell
|
|
static Widget _bodyCell(dynamic text, {bool isBold = false}) {
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 8),
|
|
alignment: Alignment.center,
|
|
child: Text(
|
|
text != null ? text.toString() : '-',
|
|
style: TextStyle(
|
|
fontWeight: isBold ? FontWeight.w600 : FontWeight.normal,
|
|
color: AppColors.textPrimary,
|
|
fontSize: 13,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|