Commit 844069e5 authored by ayodyabanuka's avatar ayodyabanuka

updated

parent 530725cc
...@@ -35,6 +35,7 @@ class _LoginState extends State<Login> { ...@@ -35,6 +35,7 @@ class _LoginState extends State<Login> {
Size size = MediaQuery.of(context).size; Size size = MediaQuery.of(context).size;
return Scaffold( return Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar( appBar: AppBar(
backgroundColor: backgroundColor, backgroundColor: backgroundColor,
elevation: 0, elevation: 0,
......
...@@ -20,6 +20,7 @@ class _registerState extends State<register> { ...@@ -20,6 +20,7 @@ class _registerState extends State<register> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size; Size size = MediaQuery.of(context).size;
return Scaffold( return Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: const Color(0xff024F8E), backgroundColor: const Color(0xff024F8E),
appBar: AppBar( appBar: AppBar(
backgroundColor: const Color(0xff024F8E), backgroundColor: const Color(0xff024F8E),
...@@ -117,6 +118,9 @@ class _registerState extends State<register> { ...@@ -117,6 +118,9 @@ class _registerState extends State<register> {
), ),
), ),
)), )),
const SizedBox(
width: 20,
),
GestureDetector( GestureDetector(
onTap: () { onTap: () {
print(emailController.text); print(emailController.text);
......
...@@ -160,14 +160,16 @@ class _foodbucketsState extends State<foodbuckets> { ...@@ -160,14 +160,16 @@ class _foodbucketsState extends State<foodbuckets> {
if (!mounted) return; if (!mounted) return;
setState(() { if (mounted) {
getResult = qrCode; setState(() {
if (buckets.contains(qrCode) || qrCode == '-1') { getResult = qrCode;
} else { if (buckets.contains(qrCode) || qrCode == '-1') {
buckets.add(qrCode); } else {
saveQRCodes(); buckets.add(qrCode);
} saveQRCodes();
}); }
});
}
print("QRCode_Result:-"); print("QRCode_Result:-");
print(qrCode); print(qrCode);
} on PlatformException { } on PlatformException {
...@@ -178,9 +180,11 @@ class _foodbucketsState extends State<foodbuckets> { ...@@ -178,9 +180,11 @@ class _foodbucketsState extends State<foodbuckets> {
saveQRCodes() { saveQRCodes() {
final user = FirebaseAuth.instance.currentUser; final user = FirebaseAuth.instance.currentUser;
if (user != null) { if (user != null) {
setState(() { if (mounted) {
name = user.displayName.toString(); setState(() {
}); name = user.displayName.toString();
});
}
} }
FirestoreServices.savefoodbuckets(buckets, name); FirestoreServices.savefoodbuckets(buckets, name);
} }
......
import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:cron/cron.dart'; import 'package:cron/cron.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart'; import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'package:ifarm/AB/Utils/Colors.dart'; import 'package:ifarm/AB/Utils/Colors.dart';
...@@ -17,16 +18,15 @@ class FoodBucketSchedule extends StatefulWidget { ...@@ -17,16 +18,15 @@ class FoodBucketSchedule extends StatefulWidget {
TextEditingController dateController = TextEditingController(); TextEditingController dateController = TextEditingController();
TextEditingController timeController = TextEditingController(); TextEditingController timeController = TextEditingController();
List<String> timeList = [];
List buckets = []; List buckets = [];
List bucketsMap = []; List bucketsMap = [];
List<String> timeList = [];
class _FoodBucketScheduleState extends State<FoodBucketSchedule> { class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
@override @override
void initState() { void initState() {
gettimelist(); gettimelist();
cancelSheduleTask(); cancelSheduleTask();
scheduleDispens();
buckets.clear(); buckets.clear();
...@@ -80,9 +80,11 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> { ...@@ -80,9 +80,11 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
print('change ${DateFormat('kk:mm').format(time)}'); print('change ${DateFormat('kk:mm').format(time)}');
}, onConfirm: (time) { }, onConfirm: (time) {
print('confirm ${DateFormat('kk:mm').format(time)}'); print('confirm ${DateFormat('kk:mm').format(time)}');
setState(() { if (mounted) {
timeController.text = DateFormat('kk:mm').format(time); setState(() {
}); timeController.text = DateFormat('kk:mm').format(time);
});
}
}, currentTime: DateTime.now(), locale: LocaleType.en); }, currentTime: DateTime.now(), locale: LocaleType.en);
}, },
controller: timeController, controller: timeController,
...@@ -109,9 +111,11 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> { ...@@ -109,9 +111,11 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
children: [ children: [
GestureDetector( GestureDetector(
onTap: () { onTap: () {
setState(() { if (mounted) {
timeController.clear(); setState(() {
}); timeController.clear();
});
}
}, },
child: Container( child: Container(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
...@@ -134,12 +138,14 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> { ...@@ -134,12 +138,14 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
GestureDetector( GestureDetector(
onTap: () { onTap: () {
if (timeController.text.isNotEmpty) { if (timeController.text.isNotEmpty) {
setState(() { if (mounted) {
timeList.add(timeController.text.toString()); setState(() {
savetimelist(); timeList.add(timeController.text.toString());
scheduleDispens(); savetimelist();
timeController.clear();
}); timeController.clear();
});
}
} }
}, },
child: Container( child: Container(
...@@ -177,7 +183,7 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> { ...@@ -177,7 +183,7 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
height: 10, height: 10,
), ),
Expanded( Expanded(
child: timeList.isEmpty child: timeList == null
? const Center( ? const Center(
child: Text( child: Text(
"No Scheduled Data", "No Scheduled Data",
...@@ -202,14 +208,12 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> { ...@@ -202,14 +208,12 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
), ),
IconButton( IconButton(
onPressed: () { onPressed: () {
setState(() { if (mounted) {
cancelSheduleTask(); setState(() {
timeList.remove(timeList[index]); timeList.remove(timeList[index]);
scheduleDispens(); savetimelist();
savetimelist(); });
NotificationService() }
.cancelNotifications(index);
});
}, },
icon: const Icon( icon: const Icon(
Icons.delete, Icons.delete,
...@@ -264,6 +268,52 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> { ...@@ -264,6 +268,52 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
}); });
}, },
)), )),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
GestureDetector(
onTap: () {
cancelSheduleTask();
},
child: Container(
padding:
const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
decoration: BoxDecoration(
border: Border.all(color: yellowButton),
borderRadius: BorderRadius.circular(10)),
height: 40,
child: const Center(
child: Text(
"Stop Schedule",
style: TextStyle(color: Colors.white),
),
),
),
),
Visibility(
visible: timeList != null,
child: GestureDetector(
onTap: () {
scheduleDispens();
},
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 20, vertical: 10),
decoration: BoxDecoration(
color: yellowButton,
borderRadius: BorderRadius.circular(10)),
height: 40,
child: const Center(
child: Text(
"Schedule Start",
style: TextStyle(color: Colors.black),
),
),
),
),
),
],
) )
], ],
), ),
...@@ -271,27 +321,61 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> { ...@@ -271,27 +321,61 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
} }
scheduleDispens() async { scheduleDispens() async {
if (timeList.isEmpty) { if (timeList == null) {
cancelSheduleTask(); cancelSheduleTask();
NotificationService().cancelAllNotifications(); NotificationService().cancelAllNotifications();
} else { } else {
print(timeList);
print(DateFormat('kk:mm').format(DateTime.now()));
for (var i = 0; i < timeList.length; i++) { for (var i = 0; i < timeList.length; i++) {
String hours = timeList[i].toString().substring(0, 2); String hours = timeList[i].toString().substring(0, 2);
String mins = timeList[i].toString().substring(3, 5); String mins = timeList[i].toString().substring(3, 5);
scheduledTask = scheduledTask =
cron.schedule(Schedule.parse("*/$mins */$hours * * *"), () async { cron.schedule(Schedule.parse("*/$mins */$hours * * *"), () async {
final servoref1 = FirebaseDatabase.instance.ref();
for (var k = 0; k < buckets.length; k++) {
print("servo run");
servoref1.update({
"Food/" + buckets[k] + "/SERVO": 1,
});
Future.delayed(const Duration(seconds: 20), () async {
print("servo closed");
await servoref1.update({
"Food/" + buckets[k] + "/SERVO": 0,
});
});
}
NotificationService().showNotification( NotificationService().showNotification(
i, 1,
"Food Dispensing", "Food Dispensing",
"Food dispensing now ${DateFormat('kk:mm').format(DateTime.now()).toString()}", "Food dispensing now ${DateFormat('kk:mm').format(DateTime.now()).toString()}",
1); 1);
}); });
print(hours + mins); print(hours + mins);
} }
print("start"); print("start");
} }
} }
dispense() async {
print('start dispensing');
for (var k = 0; k < buckets.length; k++) {
final servoref1 = FirebaseDatabase.instance.ref();
print("servo run");
servoref1.update({
"Food/" + buckets[k] + "/SERVO": 1,
});
Future.delayed(const Duration(seconds: 20), () async {
await servoref1.update({
"Food/" + buckets[k] + "/SERVO": 0,
});
});
}
}
void cancelSheduleTask() async { void cancelSheduleTask() async {
if (scheduledTask != null) { if (scheduledTask != null) {
scheduledTask.cancel(); scheduledTask.cancel();
...@@ -308,9 +392,10 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> { ...@@ -308,9 +392,10 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
gettimelist() async { gettimelist() async {
SharedPreferences timelist = await SharedPreferences.getInstance(); SharedPreferences timelist = await SharedPreferences.getInstance();
setState(() { if (mounted) {
timeList = timelist.getStringList("timelist"); setState(() {
scheduleDispens(); timeList = timelist.getStringList("timelist");
}); });
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment