264 lines
9.4 KiB
Dart
264 lines
9.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:google_fonts/google_fonts.dart';
|
|
import '../controllers/jadwal_controller.dart';
|
|
|
|
class JadwalView extends GetView<JadwalController> {
|
|
const JadwalView({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.white,
|
|
appBar: AppBar(
|
|
backgroundColor: Colors.blue,
|
|
elevation: 0,
|
|
title: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
"Hello Zidan",
|
|
style: GoogleFonts.poppins(
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.w600,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.notifications, color: Colors.white),
|
|
onPressed: controller.keNotifikasi,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
body: Obx(() {
|
|
final list = controller.jadwalList;
|
|
final interval = controller.intervalPembersih.value;
|
|
|
|
return ListView(
|
|
padding: const EdgeInsets.all(16),
|
|
children: [
|
|
Text("Otomasi Pembersih",
|
|
style: GoogleFonts.poppins(
|
|
fontSize: 18, fontWeight: FontWeight.bold)),
|
|
const SizedBox(height: 8),
|
|
Card(
|
|
margin: const EdgeInsets.symmetric(vertical: 8),
|
|
color: Colors.white,
|
|
child: Padding(
|
|
padding:
|
|
const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
"Interval: $interval menit",
|
|
style: GoogleFonts.poppins(fontSize: 16),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () =>
|
|
controller.showEditIntervalDialog(context, interval),
|
|
child: Text("Edit", style: GoogleFonts.poppins()),
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.blue,
|
|
foregroundColor: Colors.white,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 16, vertical: 8),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 24),
|
|
Text("Jadwal Pakan",
|
|
style: GoogleFonts.poppins(
|
|
fontSize: 18, fontWeight: FontWeight.bold)),
|
|
const SizedBox(height: 8),
|
|
if (list.isEmpty)
|
|
const Center(child: Text('Belum ada jadwal.'))
|
|
else
|
|
...list.map((jadwal) => Card(
|
|
margin: const EdgeInsets.symmetric(vertical: 8),
|
|
color: Colors.white,
|
|
child: ListTile(
|
|
title: Text("Jam: ${jadwal.jam}",
|
|
style: const TextStyle(
|
|
fontSize: 18, fontWeight: FontWeight.bold)),
|
|
subtitle: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text("${jadwal.takar} takar pakan",
|
|
style: const TextStyle(color: Colors.grey)),
|
|
Text("Interval: ${jadwal.intervalSet} menit",
|
|
style: const TextStyle(color: Colors.grey)),
|
|
],
|
|
),
|
|
trailing: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
IconButton(
|
|
icon: const Icon(Icons.edit, color: Colors.blue),
|
|
onPressed: () => _showInputDialog(
|
|
context,
|
|
isEdit: true,
|
|
key: jadwal.key,
|
|
jam: jadwal.jam,
|
|
takar: jadwal.takar.toString(),
|
|
interval: jadwal.intervalSet.toString(),
|
|
),
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.delete, color: Colors.red),
|
|
onPressed: () =>
|
|
controller.deleteJadwal(jadwal.key),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
)),
|
|
],
|
|
);
|
|
}),
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: () => _showInputDialog(context),
|
|
backgroundColor: Colors.lightBlue,
|
|
foregroundColor: Colors.white,
|
|
child: const Icon(Icons.add),
|
|
),
|
|
);
|
|
}
|
|
|
|
void _showInputDialog(BuildContext context,
|
|
{bool isEdit = false,
|
|
String? key,
|
|
String jam = '',
|
|
String takar = '',
|
|
String interval = ''}) {
|
|
final jamController = TextEditingController(text: jam);
|
|
final takarController = TextEditingController(text: takar);
|
|
final intervalController = TextEditingController(text: interval);
|
|
|
|
Future<void> _pickTime() async {
|
|
final TimeOfDay? picked = await showTimePicker(
|
|
context: context,
|
|
initialTime: jam.isNotEmpty
|
|
? TimeOfDay(
|
|
hour: int.tryParse(jam.split(":")[0]) ?? 0,
|
|
minute: int.tryParse(jam.split(":")[1]) ?? 0)
|
|
: TimeOfDay.now(),
|
|
);
|
|
if (picked != null) {
|
|
final formatted = picked.hour.toString().padLeft(2, '0') +
|
|
':' +
|
|
picked.minute.toString().padLeft(2, '0');
|
|
jamController.text = formatted;
|
|
}
|
|
}
|
|
|
|
Get.dialog(
|
|
AlertDialog(
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
|
title: Column(
|
|
children: [
|
|
const SizedBox(height: 10),
|
|
Text(
|
|
isEdit ? "Edit Jadwal" : "Tambah Jadwal",
|
|
style: GoogleFonts.poppins(
|
|
fontSize: 18, fontWeight: FontWeight.bold),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
],
|
|
),
|
|
content: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
TextField(
|
|
controller: jamController,
|
|
readOnly: true,
|
|
onTap: _pickTime,
|
|
decoration: InputDecoration(
|
|
labelText: 'Jam (HH:MM)',
|
|
labelStyle: GoogleFonts.poppins(),
|
|
suffixIcon: const Icon(Icons.access_time),
|
|
),
|
|
),
|
|
const SizedBox(height: 10),
|
|
TextField(
|
|
controller: takarController,
|
|
decoration: InputDecoration(
|
|
labelText: 'Takar Pakan (1 gr = 5 Takar)',
|
|
labelStyle: GoogleFonts.poppins(),
|
|
),
|
|
keyboardType: TextInputType.number,
|
|
),
|
|
const SizedBox(height: 10),
|
|
TextField(
|
|
controller: intervalController,
|
|
decoration: InputDecoration(
|
|
labelText: 'Interval Set (menit)',
|
|
labelStyle: GoogleFonts.poppins(),
|
|
),
|
|
keyboardType: TextInputType.number,
|
|
),
|
|
],
|
|
),
|
|
actions: [
|
|
ElevatedButton(
|
|
onPressed: () => Get.back(),
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.red,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
),
|
|
child:
|
|
Text('Batal', style: GoogleFonts.poppins(color: Colors.white)),
|
|
),
|
|
ElevatedButton.icon(
|
|
onPressed: () {
|
|
final jamInput = jamController.text.trim();
|
|
final takarInput = takarController.text.trim();
|
|
final intervalInput = intervalController.text.trim();
|
|
|
|
if (jamInput.isEmpty ||
|
|
takarInput.isEmpty ||
|
|
intervalInput.isEmpty) {
|
|
Get.snackbar('Error', 'Semua field harus diisi');
|
|
return;
|
|
}
|
|
|
|
final takarInt = int.tryParse(takarInput);
|
|
final intervalInt = int.tryParse(intervalInput);
|
|
|
|
if (takarInt == null || intervalInt == null || intervalInt <= 0) {
|
|
Get.snackbar('Error', 'Takar dan interval harus berupa angka');
|
|
return;
|
|
}
|
|
|
|
if (isEdit && key != null) {
|
|
controller.updateJadwal(key, jamInput, takarInt, intervalInt);
|
|
} else {
|
|
controller.addJadwal(jamInput, takarInt, intervalInt);
|
|
}
|
|
Get.back();
|
|
},
|
|
label:
|
|
Text("Simpan", style: GoogleFonts.poppins(color: Colors.white)),
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.blue,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
),
|
|
icon: const Icon(Icons.save, color: Colors.white),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|