Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
ifarm
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
TMP-2022-009
ifarm
Commits
530725cc
Commit
530725cc
authored
Nov 15, 2022
by
ayodyabanuka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update schedule
parent
d0dda92c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
166 additions
and
143 deletions
+166
-143
lib/AB/Screens/NavBar/FoodBucketSchedule.dart
lib/AB/Screens/NavBar/FoodBucketSchedule.dart
+69
-55
lib/AB/Screens/NavBar/Home.dart
lib/AB/Screens/NavBar/Home.dart
+72
-69
lib/AB/Utils/NotificationService.dart
lib/AB/Utils/NotificationService.dart
+25
-19
No files found.
lib/AB/Screens/NavBar/FoodBucketSchedule.dart
View file @
530725cc
import
'package:cloud_firestore/cloud_firestore.dart'
;
import
'package:cloud_firestore/cloud_firestore.dart'
;
import
'package:cron/cron.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'
;
import
'package:ifarm/AB/Utils/NotificationService.dart'
;
import
'package:intl/intl.dart'
;
import
'package:intl/intl.dart'
;
import
'package:shared_preferences/shared_preferences.dart'
;
class
FoodBucketSchedule
extends
StatefulWidget
{
class
FoodBucketSchedule
extends
StatefulWidget
{
FoodBucketSchedule
({
Key
key
})
:
super
(
key:
key
);
FoodBucketSchedule
({
Key
key
})
:
super
(
key:
key
);
...
@@ -14,20 +17,25 @@ class FoodBucketSchedule extends StatefulWidget {
...
@@ -14,20 +17,25 @@ class FoodBucketSchedule extends StatefulWidget {
TextEditingController
dateController
=
TextEditingController
();
TextEditingController
dateController
=
TextEditingController
();
TextEditingController
timeController
=
TextEditingController
();
TextEditingController
timeController
=
TextEditingController
();
List
dateList
=
[];
List
<
String
>
timeList
=
[];
List
timeList
=
[];
List
buckets
=
[];
List
buckets
=
[];
List
bucketsMap
=
[];
List
bucketsMap
=
[];
class
_FoodBucketScheduleState
extends
State
<
FoodBucketSchedule
>
{
class
_FoodBucketScheduleState
extends
State
<
FoodBucketSchedule
>
{
@override
@override
void
initState
()
{
void
initState
()
{
gettimelist
();
cancelSheduleTask
();
scheduleDispens
();
buckets
.
clear
();
buckets
.
clear
();
print
(
buckets
);
// TODO: implement initState
// TODO: implement initState
super
.
initState
();
super
.
initState
();
}
}
final
cron
=
Cron
();
ScheduledTask
scheduledTask
;
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
final
Stream
<
QuerySnapshot
>
bucketref
=
final
Stream
<
QuerySnapshot
>
bucketref
=
...
@@ -40,7 +48,7 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
...
@@ -40,7 +48,7 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
child:
Text
(
child:
Text
(
"Schedule your Food dispense Here!"
,
"Schedule your Food dispense Here!"
,
style:
TextStyle
(
style:
TextStyle
(
color:
Colors
.
white
,
fontWeight:
FontWeight
.
bold
,
fontSize:
2
0
),
color:
Colors
.
white
,
fontWeight:
FontWeight
.
bold
,
fontSize:
3
0
),
)),
)),
const
SizedBox
(
const
SizedBox
(
height:
40
,
height:
40
,
...
@@ -59,46 +67,6 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
...
@@ -59,46 +67,6 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
const
SizedBox
(
const
SizedBox
(
height:
10
,
height:
10
,
),
),
Container
(
decoration:
BoxDecoration
(
borderRadius:
BorderRadius
.
circular
(
15
),
color:
cardColor
),
child:
Padding
(
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
20
),
child:
TextFormField
(
readOnly:
true
,
onTap:
()
{
DatePicker
.
showDatePicker
(
context
,
showTitleActions:
true
,
minTime:
DateTime
(
2022
,
1
,
1
),
maxTime:
DateTime
(
2030
,
12
,
31
),
onChanged:
(
date
)
{
print
(
'change
${DateFormat('yyyy-MM-dd').format(date)}
'
);
},
onConfirm:
(
date
)
{
print
(
'confirm
${DateFormat('yyyy-MM-dd').format(date)}
'
);
setState
(()
{
dateController
.
text
=
DateFormat
(
'yyyy-MM-dd'
).
format
(
date
);
});
},
currentTime:
DateTime
.
now
(),
locale:
LocaleType
.
en
);
},
controller:
dateController
,
style:
const
TextStyle
(
color:
Color
.
fromARGB
(
255
,
255
,
255
,
255
)),
cursorColor:
const
Color
.
fromARGB
(
255
,
0
,
0
,
0
),
decoration:
const
InputDecoration
(
suffixIcon:
Icon
(
Icons
.
calendar_month
,
color:
Colors
.
white
,
),
hintText:
"Pick Date"
,
border:
InputBorder
.
none
,
hintStyle:
TextStyle
(
color:
Color
.
fromARGB
(
255
,
255
,
255
,
255
))),
),
),
),
const
SizedBox
(
height:
10
,
),
Container
(
Container
(
decoration:
BoxDecoration
(
decoration:
BoxDecoration
(
borderRadius:
BorderRadius
.
circular
(
15
),
color:
cardColor
),
borderRadius:
BorderRadius
.
circular
(
15
),
color:
cardColor
),
...
@@ -143,7 +111,6 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
...
@@ -143,7 +111,6 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
onTap:
()
{
onTap:
()
{
setState
(()
{
setState
(()
{
timeController
.
clear
();
timeController
.
clear
();
dateController
.
clear
();
});
});
},
},
child:
Container
(
child:
Container
(
...
@@ -162,16 +129,15 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
...
@@ -162,16 +129,15 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
),
),
)),
)),
const
SizedBox
(
const
SizedBox
(
width:
1
0
,
width:
3
0
,
),
),
GestureDetector
(
GestureDetector
(
onTap:
()
{
onTap:
()
{
if
(
dateController
.
text
.
isNotEmpty
&&
if
(
timeController
.
text
.
isNotEmpty
)
{
timeController
.
text
.
isNotEmpty
)
{
setState
(()
{
setState
(()
{
dateList
.
add
(
dateController
.
text
);
timeList
.
add
(
timeController
.
text
.
toString
()
);
timeList
.
add
(
timeController
.
text
);
savetimelist
(
);
dateController
.
clear
();
scheduleDispens
();
timeController
.
clear
();
timeController
.
clear
();
});
});
}
}
...
@@ -211,7 +177,7 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
...
@@ -211,7 +177,7 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
height:
10
,
height:
10
,
),
),
Expanded
(
Expanded
(
child:
dat
eList
.
isEmpty
child:
tim
eList
.
isEmpty
?
const
Center
(
?
const
Center
(
child:
Text
(
child:
Text
(
"No Scheduled Data"
,
"No Scheduled Data"
,
...
@@ -219,7 +185,7 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
...
@@ -219,7 +185,7 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
),
),
)
)
:
ListView
.
builder
(
:
ListView
.
builder
(
itemCount:
dat
eList
.
length
,
itemCount:
tim
eList
.
length
,
itemBuilder:
(
context
,
index
)
{
itemBuilder:
(
context
,
index
)
{
return
Container
(
return
Container
(
margin:
const
EdgeInsets
.
symmetric
(
vertical:
5
),
margin:
const
EdgeInsets
.
symmetric
(
vertical:
5
),
...
@@ -231,14 +197,18 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
...
@@ -231,14 +197,18 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
mainAxisAlignment:
MainAxisAlignment
.
spaceBetween
,
mainAxisAlignment:
MainAxisAlignment
.
spaceBetween
,
children:
[
children:
[
Text
(
Text
(
"
Date:
${dateList[index]}
Time:
${timeList[index]}
"
,
"Time:
${timeList[index]}
"
,
style:
const
TextStyle
(
color:
Colors
.
white
),
style:
const
TextStyle
(
color:
Colors
.
white
),
),
),
IconButton
(
IconButton
(
onPressed:
()
{
onPressed:
()
{
setState
(()
{
setState
(()
{
dateList
.
remove
(
dateList
[
index
]
);
cancelSheduleTask
(
);
timeList
.
remove
(
timeList
[
index
]);
timeList
.
remove
(
timeList
[
index
]);
scheduleDispens
();
savetimelist
();
NotificationService
()
.
cancelNotifications
(
index
);
});
});
},
},
icon:
const
Icon
(
icon:
const
Icon
(
...
@@ -299,4 +269,48 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
...
@@ -299,4 +269,48 @@ class _FoodBucketScheduleState extends State<FoodBucketSchedule> {
),
),
);
);
}
}
scheduleDispens
()
async
{
if
(
timeList
.
isEmpty
)
{
cancelSheduleTask
();
NotificationService
().
cancelAllNotifications
();
}
else
{
for
(
var
i
=
0
;
i
<
timeList
.
length
;
i
++)
{
String
hours
=
timeList
[
i
].
toString
().
substring
(
0
,
2
);
String
mins
=
timeList
[
i
].
toString
().
substring
(
3
,
5
);
scheduledTask
=
cron
.
schedule
(
Schedule
.
parse
(
"*/
$mins
*/
$hours
* * *"
),
()
async
{
NotificationService
().
showNotification
(
i
,
"Food Dispensing"
,
"Food dispensing now
${DateFormat('kk:mm').format(DateTime.now()).toString()}
"
,
1
);
});
print
(
hours
+
mins
);
}
print
(
"start"
);
}
}
void
cancelSheduleTask
()
async
{
if
(
scheduledTask
!=
null
)
{
scheduledTask
.
cancel
();
}
print
(
"cancel"
);
}
savetimelist
()
async
{
SharedPreferences
timelist
=
await
SharedPreferences
.
getInstance
();
timelist
.
setStringList
(
"timelist"
,
timeList
);
}
gettimelist
()
async
{
SharedPreferences
timelist
=
await
SharedPreferences
.
getInstance
();
setState
(()
{
timeList
=
timelist
.
getStringList
(
"timelist"
);
scheduleDispens
();
});
}
}
}
lib/AB/Screens/NavBar/Home.dart
View file @
530725cc
...
@@ -50,6 +50,9 @@ class _HomeState extends State<Home> {
...
@@ -50,6 +50,9 @@ class _HomeState extends State<Home> {
child:
Column
(
child:
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
start
,
crossAxisAlignment:
CrossAxisAlignment
.
start
,
children:
[
children:
[
const
SizedBox
(
height:
40
,
),
Container
(
Container
(
padding:
const
EdgeInsets
.
all
(
25
),
padding:
const
EdgeInsets
.
all
(
25
),
decoration:
BoxDecoration
(
decoration:
BoxDecoration
(
...
@@ -246,65 +249,65 @@ class _HomeState extends State<Home> {
...
@@ -246,65 +249,65 @@ class _HomeState extends State<Home> {
),
),
],
],
),
),
GestureDetector
(
//
GestureDetector(
onTap:
()
{
//
onTap: () {
NotificationService
()
//
NotificationService()
.
showNotification
(
1
,
"title"
,
"body"
,
3
);
//
.showNotification(1, "title", "body", 3);
},
//
},
child:
Container
(
//
child: Container(
height:
40
,
//
height: 40,
width:
200
,
//
width: 200,
color:
Colors
.
green
,
//
color: Colors.green,
child:
Center
(
//
child: Center(
child:
Text
(
"Show Notification"
),
//
child: Text("Show Notification"),
),
//
),
),
//
),
),
//
),
GestureDetector
(
//
GestureDetector(
onTap:
()
{
//
onTap: () {
NotificationService
().
cancelAllNotifications
();
//
NotificationService().cancelAllNotifications();
},
//
},
child:
Container
(
//
child: Container(
height:
40
,
//
height: 40,
width:
200
,
//
width: 200,
color:
Colors
.
red
,
//
color: Colors.red,
child:
Center
(
//
child: Center(
child:
Text
(
//
child: Text(
"Cancel All Notifications"
,
//
"Cancel All Notifications",
),
//
),
),
//
),
),
//
),
),
//
),
GestureDetector
(
//
GestureDetector(
onTap:
()
{
//
onTap: () {
scheduleTask
();
//
scheduleTask();
},
//
},
child:
Container
(
//
child: Container(
height:
40
,
//
height: 40,
width:
200
,
//
width: 200,
color:
Color
.
fromARGB
(
255
,
255
,
255
,
255
),
//
color: Color.fromARGB(255, 255, 255, 255),
child:
Center
(
//
child: Center(
child:
Text
(
//
child: Text(
"Schedule"
,
//
"Schedule",
),
//
),
),
//
),
),
//
),
),
//
),
GestureDetector
(
//
GestureDetector(
onTap:
()
{
//
onTap: () {
cancelSheduleTask
();
//
cancelSheduleTask();
},
//
},
child:
Container
(
//
child: Container(
height:
40
,
//
height: 40,
width:
200
,
//
width: 200,
color:
Color
.
fromARGB
(
255
,
255
,
255
,
255
),
//
color: Color.fromARGB(255, 255, 255, 255),
child:
Center
(
//
child: Center(
child:
Text
(
//
child: Text(
"Cancel Schedule"
,
//
"Cancel Schedule",
),
//
),
),
//
),
),
//
),
),
//
),
],
],
),
),
],
],
...
@@ -312,15 +315,15 @@ class _HomeState extends State<Home> {
...
@@ -312,15 +315,15 @@ class _HomeState extends State<Home> {
);
);
}
}
void
scheduleTask
()
async
{
//
void scheduleTask() async {
scheduledTask
=
cron
.
schedule
(
Schedule
.
parse
(
"*/1 * * * *"
),
()
async
{
//
scheduledTask = cron.schedule(Schedule.parse("*/1 * * * *"), () async {
NotificationService
().
showNotification
(
2
,
"Food Dispensing"
,
//
NotificationService().showNotification(2, "Food Dispensing",
"Food dispensing now
${DateTime.now().toString()}
"
,
1
);
//
"Food dispensing now ${DateTime.now().toString()}", 1);
});
//
});
}
//
}
void
cancelSheduleTask
()
async
{
//
void cancelSheduleTask() async {
scheduledTask
.
cancel
();
//
scheduledTask.cancel();
print
(
"cancel"
);
//
print("cancel");
}
//
}
}
}
lib/AB/Utils/NotificationService.dart
View file @
530725cc
...
@@ -37,29 +37,35 @@ class NotificationService {
...
@@ -37,29 +37,35 @@ class NotificationService {
Future
<
void
>
showNotification
(
Future
<
void
>
showNotification
(
int
id
,
String
title
,
String
body
,
int
seconds
)
async
{
int
id
,
String
title
,
String
body
,
int
seconds
)
async
{
await
flutterLocalNotificationsPlugin
.
zonedSchedule
(
await
flutterLocalNotificationsPlugin
.
zonedSchedule
(
id
,
id
,
title
,
title
,
body
,
body
,
tz
.
TZDateTime
.
now
(
tz
.
local
).
add
(
Duration
(
seconds:
seconds
)),
tz
.
TZDateTime
.
now
(
tz
.
local
).
add
(
Duration
(
seconds:
seconds
)),
const
NotificationDetails
(
const
NotificationDetails
(
android:
AndroidNotificationDetails
(
android:
AndroidNotificationDetails
(
'main_channel'
,
'Main Channel'
,
'Main channel notifications'
,
'main_channel'
,
'Main Channel'
,
'Main channel notifications'
,
importance:
Importance
.
max
,
importance:
Importance
.
max
,
priority:
Priority
.
max
,
priority:
Priority
.
max
,
icon:
'@drawable/ifarm_icon_blue'
),
icon:
'@drawable/ifarm_icon_blue'
),
iOS:
IOSNotificationDetails
(
iOS:
IOSNotificationDetails
(
presentAlert:
true
,
presentAlert:
true
,
presentBadge:
true
,
presentBadge:
true
,
presentSound:
true
,
presentSound:
true
,
),
),
),
),
uiLocalNotificationDateInterpretation:
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation
.
absoluteTime
,
UILocalNotificationDateInterpretation
.
absoluteTime
,
androidAllowWhileIdle:
true
,
androidAllowWhileIdle:
true
,
payload:
"Start Dispense"
);
);
}
}
Future
selectNotification
(
String
payload
)
async
{}
Future
<
void
>
cancelAllNotifications
()
async
{
Future
<
void
>
cancelAllNotifications
()
async
{
await
flutterLocalNotificationsPlugin
.
cancelAll
();
await
flutterLocalNotificationsPlugin
.
cancelAll
();
}
}
Future
<
void
>
cancelNotifications
(
int
id
)
async
{
await
flutterLocalNotificationsPlugin
.
cancel
(
id
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment