TKK_E32231105/lib/screens/riwayat_page.dart

369 lines
13 KiB
Dart

import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import '../providers/panen_provider.dart';
class RiwayatPage extends StatefulWidget {
const RiwayatPage({super.key});
@override
State<RiwayatPage> createState() => _RiwayatPageState();
}
class _RiwayatPageState extends State<RiwayatPage> {
DateTime? _selectedStartDate;
DateTime? _selectedEndDate;
@override
void initState() {
super.initState();
_selectedStartDate = DateTime.now().subtract(const Duration(days: 7));
_selectedEndDate = DateTime.now();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.orange.shade100,
Colors.amber.shade100,
Colors.greenAccent.shade100,
],
),
),
child: SafeArea(
child: Column(
children: [
// Filter Section
Container(
color: Colors.white,
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Filter Tanggal',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.grey.shade800,
),
),
const SizedBox(height: 12),
Row(
children: [
Expanded(
child: InkWell(
onTap: _selectStartDate,
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 10,
),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey.shade300),
borderRadius: BorderRadius.circular(8),
),
child: Row(
children: [
const Icon(Icons.calendar_today, size: 18),
const SizedBox(width: 8),
Text(
_selectedStartDate != null
? DateFormat(
'dd/MM/yyyy',
).format(_selectedStartDate!)
: 'Mulai',
style: const TextStyle(fontSize: 12),
),
],
),
),
),
),
const SizedBox(width: 8),
Text(
'sd',
style: TextStyle(color: Colors.grey.shade600),
),
const SizedBox(width: 8),
Expanded(
child: InkWell(
onTap: _selectEndDate,
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 10,
),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey.shade300),
borderRadius: BorderRadius.circular(8),
),
child: Row(
children: [
const Icon(Icons.calendar_today, size: 18),
const SizedBox(width: 8),
Text(
_selectedEndDate != null
? DateFormat(
'dd/MM/yyyy',
).format(_selectedEndDate!)
: 'Akhir',
style: const TextStyle(fontSize: 12),
),
],
),
),
),
),
],
),
],
),
),
// Content
Expanded(child: _buildRiwayatList()),
],
),
),
),
);
}
Widget _buildRiwayatList() {
final panenProvider = context.watch<PanenProvider>();
List<dynamic> panens = [];
if (_selectedStartDate != null && _selectedEndDate != null) {
panens = panenProvider.getPanenByDateRange(
_selectedStartDate!,
_selectedEndDate!,
);
}
if (panens.isEmpty) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('📭', style: TextStyle(fontSize: 64)),
const SizedBox(height: 16),
Text(
'Tidak ada data panen',
style: TextStyle(
fontSize: 16,
color: Colors.grey.shade600,
fontWeight: FontWeight.bold,
),
),
],
),
);
}
return SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Total Harian Summary
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.orange.shade300, Colors.orange.shade600],
),
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.orange.shade300.withOpacity(0.3),
blurRadius: 10,
offset: const Offset(0, 5),
),
],
),
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Total Produksi',
style: TextStyle(
fontSize: 14,
color: Colors.white.withOpacity(0.9),
fontWeight: FontWeight.w500,
),
),
const SizedBox(height: 12),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'${panens.isEmpty ? 0 : panens.map<int>((p) => p.jumlahTelur).reduce((a, b) => a + b)}',
style: const TextStyle(
fontSize: 36,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
const SizedBox(height: 4),
Text(
'telur',
style: TextStyle(
fontSize: 12,
color: Colors.white.withOpacity(0.8),
),
),
],
),
Text('🥚', style: TextStyle(fontSize: 48)),
],
),
const SizedBox(height: 12),
Text(
'${panens.length} pencatatan panen',
style: TextStyle(
fontSize: 12,
color: Colors.white.withOpacity(0.8),
),
),
],
),
),
const SizedBox(height: 24),
// Breakdown per hari
Text(
'Detail Panen Per Hari',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.grey.shade800,
),
),
const SizedBox(height: 12),
ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: panens.length,
itemBuilder: (context, index) {
final panen = panens[index];
final tanggal = DateFormat(
'dd MMMM yyyy',
).format(panen.tanggalPanen);
return Container(
margin: const EdgeInsets.only(bottom: 12),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
panen.kandangNama,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 4),
Text(
'$tanggal${panen.jam}',
style: TextStyle(
fontSize: 12,
color: Colors.grey.shade600,
),
),
],
),
Container(
decoration: BoxDecoration(
color: Colors.orange.shade100,
borderRadius: BorderRadius.circular(12),
),
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 8,
),
child: Column(
children: [
Text(
'${panen.jumlahTelur}',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.orange.shade700,
),
),
Text('🥚', style: TextStyle(fontSize: 16)),
],
),
),
],
),
],
),
),
);
},
),
],
),
);
}
Future<void> _selectStartDate() async {
final DateTime? picked = await showDatePicker(
context: context,
initialDate: _selectedStartDate ?? DateTime.now(),
firstDate: DateTime(2020),
lastDate: DateTime.now(),
);
if (picked != null) {
setState(() {
_selectedStartDate = picked;
});
}
}
Future<void> _selectEndDate() async {
final DateTime? picked = await showDatePicker(
context: context,
initialDate: _selectedEndDate ?? DateTime.now(),
firstDate: DateTime(2020),
lastDate: DateTime.now(),
);
if (picked != null) {
setState(() {
_selectedEndDate = picked;
});
}
}
}