274 lines
8.2 KiB
Dart
274 lines
8.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import '../controllers/home_controller.dart';
|
|
import 'package:intl/intl.dart';
|
|
|
|
|
|
class HomeView extends GetView<HomeController> {
|
|
const HomeView({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: SingleChildScrollView(
|
|
child: Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 40.0),
|
|
decoration: const BoxDecoration(
|
|
gradient: LinearGradient(
|
|
begin: Alignment.topCenter,
|
|
end: Alignment.bottomCenter,
|
|
colors: [
|
|
Color(0xFF7EFAB7),
|
|
Color(0xFF4FB9E4),
|
|
],
|
|
),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// Top Greeting & Notification
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
const Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'Hello Akbar,',
|
|
style: TextStyle(
|
|
fontSize: 30,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
SizedBox(height: 4),
|
|
Text(
|
|
'Selamat datang!',
|
|
style: TextStyle(
|
|
fontSize: 20,
|
|
color: Colors.white70,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.notifications_none, color: Colors.white, size: 32),
|
|
onPressed: controller.keNotifikasi,
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 20),
|
|
|
|
// Weather Card
|
|
Obx(() => Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.all(16.0),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white.withOpacity(0.2),
|
|
borderRadius: BorderRadius.circular(20),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
Row(
|
|
children: [
|
|
const Icon(Icons.wb_cloudy_outlined, size: 48, color: Colors.white),
|
|
const SizedBox(width: 16),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'${controller.temperature.value} ${controller.description.value}',
|
|
style: const TextStyle(
|
|
fontSize: 18,
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
const Text(
|
|
'Jember',
|
|
style: TextStyle(
|
|
color: Colors.white70,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
DateFormat('EEEE, dd MMMM yyyy', 'id_ID').format(DateTime.now()),
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
|
|
],
|
|
),
|
|
)),
|
|
const SizedBox(height: 30),
|
|
|
|
const Text(
|
|
'Menu',
|
|
style: TextStyle(
|
|
color: Color(0xFF240038),
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 18,
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
|
|
// Menu Buttons
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
_menuItem(Icons.map, "Maps Lokasi", controller.keMaps),
|
|
_menuItem(Icons.history, "History Data", controller.keHistory),
|
|
],
|
|
),
|
|
const SizedBox(height: 30),
|
|
|
|
const Text(
|
|
'Kontrol Alat',
|
|
style: TextStyle(
|
|
color: Color(0xFF240038),
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 18,
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
|
|
// Relay Control
|
|
Obx(() => GestureDetector(
|
|
onTap: controller.toggleRelay,
|
|
child: _controlItem(
|
|
icon: Icons.electrical_services,
|
|
label: "Control Machine",
|
|
status: controller.relay.value ? "ON" : "OFF",
|
|
color: controller.relay.value ? Colors.green : Colors.orange,
|
|
),
|
|
)),
|
|
const SizedBox(height: 16),
|
|
|
|
// Buzzer Control
|
|
Obx(() => GestureDetector(
|
|
onTap: controller.toggleBuzzer,
|
|
child: _controlItem(
|
|
icon: Icons.local_fire_department,
|
|
label: "Buzzer Emergency",
|
|
status: controller.buzzer.value ? "ON" : "OFF",
|
|
color: controller.buzzer.value ? Colors.redAccent : Colors.grey,
|
|
),
|
|
)),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _menuItem(IconData icon, String label, VoidCallback onTap) {
|
|
return Expanded(
|
|
child: GestureDetector(
|
|
onTap: onTap,
|
|
child: Container(
|
|
margin: const EdgeInsets.symmetric(horizontal: 8.0),
|
|
padding: const EdgeInsets.all(16.0),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(20),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
ShaderMask(
|
|
shaderCallback: (Rect bounds) {
|
|
return const LinearGradient(
|
|
colors: [
|
|
Color(0xFF7EFAB7),
|
|
Color(0xFF4FB9E4),
|
|
],
|
|
begin: Alignment.topCenter,
|
|
end: Alignment.bottomCenter,
|
|
).createShader(bounds);
|
|
},
|
|
child: Icon(
|
|
icon, // ← Ikon dari parameter
|
|
size: 40,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
const SizedBox(height: 10),
|
|
Text(
|
|
label,
|
|
textAlign: TextAlign.center,
|
|
style: const TextStyle(
|
|
color: Color(0xFF240038),
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _controlItem({
|
|
required IconData icon,
|
|
required String label,
|
|
required String status,
|
|
required Color color,
|
|
}) {
|
|
return Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.all(16.0),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(20),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Icon(icon, color: color, size: 36),
|
|
const SizedBox(width: 16),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
label,
|
|
style: const TextStyle(color: Colors.grey),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
status,
|
|
style: const TextStyle(
|
|
color: Color(0xFF240038),
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
String _getMonthName(int month) {
|
|
const months = [
|
|
'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni',
|
|
'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember'
|
|
];
|
|
return months[month - 1];
|
|
}
|
|
|
|
String _getDayName(int weekday) {
|
|
const days = [
|
|
'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu', 'Minggu'
|
|
];
|
|
return days[weekday - 1];
|
|
}
|
|
}
|