115 lines
3.5 KiB
Dart
115 lines
3.5 KiB
Dart
import 'package:firebase_database/firebase_database.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:intl/intl.dart';
|
|
|
|
class pakan extends StatefulWidget {
|
|
const pakan({super.key});
|
|
|
|
@override
|
|
State<pakan> createState() => _pakanState();
|
|
}
|
|
|
|
class _pakanState extends State<pakan> {
|
|
bool motorStatus = false;
|
|
String currentDate = "";
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_updateDate();
|
|
}
|
|
|
|
void _updateDate() {
|
|
final now = DateTime.now();
|
|
final formattedDate = DateFormat('EEEE, d MMMM yyyy','id_ID').format(now);
|
|
setState(() {
|
|
currentDate = formattedDate;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: ListView(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 30, right: 30, top: 20),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
"Hari ini",
|
|
style: TextStyle(
|
|
fontSize: 25,
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
Text(
|
|
currentDate,
|
|
style: TextStyle(
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 10),
|
|
padding: EdgeInsets.all(10),
|
|
width: MediaQuery.of(context).size.width,
|
|
child: Text("Beri makan ayam disini !"),
|
|
decoration: BoxDecoration(
|
|
color: Color.fromARGB(255, 86, 238, 16).withOpacity(0.7),
|
|
borderRadius: BorderRadius.circular(5),
|
|
),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 45, bottom: 110),
|
|
child: Image.asset("images/farm.png"),
|
|
),
|
|
SizedBox(
|
|
width: 400,
|
|
height: 40,
|
|
child: MaterialButton(
|
|
elevation: 0,
|
|
onPressed: () {
|
|
DatabaseReference databaseReference = FirebaseDatabase
|
|
.instance
|
|
.reference()
|
|
.child('pakan')
|
|
.child('motor_status');
|
|
|
|
if (motorStatus) {
|
|
databaseReference.set(false);
|
|
setState(() {
|
|
motorStatus = false;
|
|
});
|
|
} else {
|
|
databaseReference.set(true);
|
|
setState(() {
|
|
motorStatus = true;
|
|
});
|
|
}
|
|
},
|
|
child: Text(motorStatus ? "Stop" : "Start",
|
|
style: TextStyle(
|
|
color: Color(0xffffffff))), // Mengubah teks tombol
|
|
color: motorStatus ? Colors.red : Colors.orange,
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 34),
|
|
child: Center(
|
|
child: Text(
|
|
"Copyright @2023 Team Dev MBKM All Right Reserved",
|
|
style: TextStyle(fontSize: 11),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|