This commit is contained in:
Mochamad ongki ramadani 2026-06-21 15:16:57 +07:00
parent 096a0fd928
commit 35d5165711
1 changed files with 32 additions and 109 deletions

View File

@ -101,7 +101,7 @@ class _HeaderBar extends StatelessWidget {
return Row(
children: [
const Text(
'Riwayat Data',
'History Evaporasi Harian',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
@ -171,32 +171,22 @@ class _ChipButton extends StatelessWidget {
//
// Group per tanggal
//
class _DateGroup extends StatefulWidget {
class _DateGroup extends StatelessWidget {
final String label;
final List<Evaporasi> items;
const _DateGroup({required this.label, required this.items});
@override
State<_DateGroup> createState() => _DateGroupState();
}
class _DateGroupState extends State<_DateGroup> {
bool _expanded = true;
double get _avgEvap {
if (widget.items.isEmpty) return 0;
return widget.items.map((e) => e.evaporasi).reduce((a, b) => a + b) /
widget.items.length;
if (items.isEmpty) return 0;
return items.map((e) => e.evaporasi).reduce((a, b) => a + b) / items.length;
}
double get _avgTemp {
if (widget.items.isEmpty) return 0;
final validTemps =
widget.items.where((e) => e.suhu >= -50 && e.suhu <= 100).toList();
if (items.isEmpty) return 0;
final validTemps = items.where((e) => e.suhu >= -50 && e.suhu <= 100).toList();
if (validTemps.isEmpty) return 0;
return validTemps.map((e) => e.suhu).reduce((a, b) => a + b) /
validTemps.length;
return validTemps.map((e) => e.suhu).reduce((a, b) => a + b) / validTemps.length;
}
@override
@ -214,13 +204,8 @@ class _DateGroupState extends State<_DateGroup> {
),
],
),
child: Column(
children: [
InkWell(
onTap: () => setState(() => _expanded = !_expanded),
borderRadius: const BorderRadius.vertical(top: Radius.circular(16)),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
child: Row(
children: [
Container(
@ -236,82 +221,20 @@ class _DateGroupState extends State<_DateGroup> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(widget.label,
Text(label,
style: const TextStyle(
fontWeight: FontWeight.bold, fontSize: 13)),
const SizedBox(height: 2),
const SizedBox(height: 6),
Text(
'${widget.items.length} data • rata-rata ${_avgEvap.toStringAsFixed(2)} mm • suhu rata-rata ${_avgTemp.toStringAsFixed(1)} °C',
style: TextStyle(fontSize: 11, color: Colors.grey.shade600),
),
],
),
),
Icon(
_expanded
? Icons.keyboard_arrow_up_rounded
: Icons.keyboard_arrow_down_rounded,
color: Colors.grey.shade500,
),
],
),
),
),
if (_expanded)
ListView.separated(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: widget.items.length,
separatorBuilder: (_, __) => Divider(height: 1, color: Colors.grey.shade100),
itemBuilder: (context, i) => _HistoryItemTile(item: widget.items[i]),
),
],
),
);
}
}
class _HistoryItemTile extends StatelessWidget {
final Evaporasi item;
const _HistoryItemTile({required this.item});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
child: Row(
children: [
SizedBox(
width: 52,
child: Text(
DateFormat('HH:mm:ss').format(item.timestamp),
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
fontFamily: 'monospace',
),
),
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'${item.evaporasi.toStringAsFixed(2)} mm • ${item.suhu.toStringAsFixed(1)} °C • ${item.tinggiAir.toStringAsFixed(1)} cm',
style: const TextStyle(fontSize: 13, color: Colors.black87),
),
const SizedBox(height: 4),
Text(
item.status,
style: TextStyle(fontSize: 11, color: Colors.grey.shade600),
'rata-rata evaporasi ${_avgEvap.toStringAsFixed(2)} mm • rata-rata suhu ${_avgTemp.toStringAsFixed(1)} °C',
style: TextStyle(fontSize: 12, color: Colors.grey.shade600),
),
],
),
),
],
),
),
);
}
}