367 lines
13 KiB
Dart
367 lines
13 KiB
Dart
import 'package:firebase_auth/firebase_auth.dart';
|
|
import 'package:flutter/material.dart';
|
|
// import 'package:flutter/widgets.dart';
|
|
import 'package:ternak/animal_menu.dart';
|
|
import 'package:ternak/cage_menu.dart';
|
|
import 'package:ternak/healthy_add.dart';
|
|
import 'package:ternak/laporan.dart';
|
|
|
|
class Home extends StatefulWidget {
|
|
final User user;
|
|
final int countAnimal;
|
|
final int countMale;
|
|
final int countFemale;
|
|
final int countHealthy;
|
|
final int countSick;
|
|
final Function getData;
|
|
const Home(
|
|
{super.key,
|
|
required this.user,
|
|
this.countAnimal = 0,
|
|
this.countMale = 0,
|
|
this.countFemale = 0,
|
|
this.countHealthy = 0,
|
|
this.countSick = 0,
|
|
required this.getData});
|
|
|
|
@override
|
|
State<Home> createState() => _HomeState();
|
|
}
|
|
|
|
class _HomeState extends State<Home> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
decoration: const BoxDecoration(
|
|
gradient: LinearGradient(
|
|
begin: Alignment.topCenter,
|
|
end: Alignment.bottomCenter,
|
|
colors: [Colors.white, Color(0xFFF5F5F5)],
|
|
),
|
|
),
|
|
padding: const EdgeInsets.symmetric(horizontal: 15),
|
|
child: Center(
|
|
child: ListView(
|
|
children: [
|
|
const SizedBox(height: 20),
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(20),
|
|
gradient: const LinearGradient(
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
colors: [
|
|
Color(0xFF1D91AA),
|
|
Color(0xFF25A5C4),
|
|
],
|
|
),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withOpacity(0.1),
|
|
spreadRadius: 0,
|
|
blurRadius: 15,
|
|
offset: const Offset(0, 5),
|
|
),
|
|
],
|
|
),
|
|
child: Container(
|
|
padding: const EdgeInsets.all(10),
|
|
child: Column(
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(10),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(15),
|
|
),
|
|
child: Image.asset(
|
|
"assets/images/icon-cage.png",
|
|
height: 40,
|
|
),
|
|
),
|
|
const SizedBox(width: 15),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Text(
|
|
"Domba",
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.w900,
|
|
fontSize: 20,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
const SizedBox(height: 5),
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 12,
|
|
vertical: 6,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white.withOpacity(0.2),
|
|
borderRadius: BorderRadius.circular(20),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
const Text(
|
|
"Total Populasi: ",
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
Text(
|
|
"${widget.countAnimal} Ekor",
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
],
|
|
)
|
|
],
|
|
),
|
|
const SizedBox(height: 6),
|
|
Container(
|
|
padding: const EdgeInsets.all(6),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
_buildStatCard(
|
|
icon: Icons.male,
|
|
label: "Jantan",
|
|
count: widget.countMale,
|
|
),
|
|
_buildStatCard(
|
|
icon: Icons.female,
|
|
label: "Betina",
|
|
count: widget.countFemale,
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 12),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
_buildStatCard(
|
|
icon: Icons.local_activity_outlined,
|
|
label: "Sehat",
|
|
count: widget.countHealthy,
|
|
iconColor: Colors.green,
|
|
),
|
|
_buildStatCard(
|
|
icon: Icons.healing,
|
|
label: "Sakit",
|
|
count: widget.countSick,
|
|
iconColor: Colors.red,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 10),
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 10),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Padding(
|
|
padding: EdgeInsets.only(left: 5, bottom: 10),
|
|
child: Text(
|
|
"Menu Utama",
|
|
style: TextStyle(
|
|
fontSize: 15,
|
|
fontWeight: FontWeight.bold,
|
|
color: Color(0xFF1D91AA),
|
|
),
|
|
),
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
_buildMenuCard(
|
|
context: context,
|
|
imagePath: "assets/images/Domba-fix.png",
|
|
label: "Hewan",
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => MenuAnimal(
|
|
user: widget.user,
|
|
),
|
|
),
|
|
).then((value) => widget.getData());
|
|
},
|
|
),
|
|
_buildMenuCard(
|
|
context: context,
|
|
imagePath: "assets/images/Kandangr.png",
|
|
label: "Kandang",
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => CageMenu(
|
|
user: widget.user,
|
|
),
|
|
),
|
|
).then((value) => widget.getData());
|
|
},
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 10),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
_buildMenuCard(
|
|
context: context,
|
|
imagePath: "assets/images/kesehatanr.png",
|
|
label: "Keterangan",
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => HealthyAdd(
|
|
user: widget.user,
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
_buildMenuCard(
|
|
context: context,
|
|
imagePath: "assets/images/laporanr.png",
|
|
label: "Laporan",
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => LaporanScreen(
|
|
user: widget.user,
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildStatCard({
|
|
required IconData icon,
|
|
required String label,
|
|
required int count,
|
|
Color iconColor = const Color(0xFF1D91AA),
|
|
}) {
|
|
return Container(
|
|
width: 120,
|
|
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 15),
|
|
decoration: BoxDecoration(
|
|
color: iconColor.withOpacity(0.1),
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(
|
|
icon,
|
|
color: iconColor,
|
|
size: 24,
|
|
),
|
|
const SizedBox(width: 8),
|
|
Text(
|
|
label,
|
|
style: TextStyle(
|
|
color: iconColor,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
"$count Ekor",
|
|
style: TextStyle(
|
|
color: iconColor,
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 16,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildMenuCard({
|
|
required BuildContext context,
|
|
required String imagePath,
|
|
required String label,
|
|
required VoidCallback onTap,
|
|
}) {
|
|
return GestureDetector(
|
|
onTap: onTap,
|
|
child: Container(
|
|
width: MediaQuery.of(context).size.width * 0.4,
|
|
padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(20),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withOpacity(0.05),
|
|
spreadRadius: 0,
|
|
blurRadius: 10,
|
|
offset: const Offset(0, 5),
|
|
),
|
|
],
|
|
),
|
|
child: Column(
|
|
children: [
|
|
Image.asset(
|
|
imagePath,
|
|
width: 80,
|
|
height: 80,
|
|
fit: BoxFit.contain,
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
label,
|
|
style: const TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 14,
|
|
color: Color(0xFF1D91AA),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} |