1
+ import 'package:flutter/material.dart' ;
2
+ import 'package:flutter_local_notifications/flutter_local_notifications.dart' ;
3
+ import 'dart:typed_data' ;
4
+
5
+ NotificationDetails getNotificationDetails (){
6
+ AndroidNotificationDetails android = AndroidNotificationDetails (
7
+ 'channel_id' ,
8
+ 'channel_name' ,
9
+ 'channel_description' ,
10
+
11
+ visibility: NotificationVisibility .Public ,
12
+ priority: Priority .Max ,
13
+ importance: Importance .Max ,
14
+
15
+ ledColor: const Color .fromARGB (255 ,0 , 200 , 255 ),
16
+ ledOffMs: 500 ,
17
+ ledOnMs: 300 ,
18
+
19
+ enableLights: true ,
20
+
21
+ color: Colors .blue,
22
+
23
+ additionalFlags: Int32List .fromList ([8 ]),
24
+ category: 'reminder' ,
25
+
26
+ playSound: true ,
27
+ sound: RawResourceAndroidNotificationSound ('notification_sound' ),
28
+
29
+ enableVibration: true ,
30
+ vibrationPattern: Int64List .fromList ([0 ,1000 ,1000 ,1000 ]),
31
+ );
32
+ IOSNotificationDetails ios = IOSNotificationDetails ();
33
+ NotificationDetails details = NotificationDetails (android, ios);
34
+ return details;
35
+ }
36
+
37
+ Future <void > setDailyStartNotification (TimeOfDay time, String user)async {
38
+ try {
39
+ FlutterLocalNotificationsPlugin plugin = FlutterLocalNotificationsPlugin ();
40
+ NotificationDetails notificationDetails = getNotificationDetails ();
41
+ await plugin.cancel (0 );
42
+ await plugin.showDailyAtTime (
43
+ 0 ,
44
+ "Good Morning, $user " ,
45
+ "Don't forget to dring enoung water today" ,
46
+ Time (time.hour,time.minute),
47
+ notificationDetails
48
+ );
49
+ }catch (e){
50
+ print (e);
51
+ }
52
+ }
53
+
54
+ Future <void > waterNotification (int left)async {
55
+ try {
56
+ FlutterLocalNotificationsPlugin plugin = FlutterLocalNotificationsPlugin ();
57
+ NotificationDetails notificationDetails = getNotificationDetails ();
58
+ await plugin.cancel (1 );
59
+ await plugin.schedule (
60
+ 1 ,
61
+ "Hey, it's time to drink water" ,
62
+ "$left mL water left to drink today" ,
63
+ DateTime .now ().add (Duration (hours: 1 ,minutes: 30 )),
64
+ notificationDetails
65
+ );
66
+ }catch (e){
67
+ print (e);
68
+ }
69
+ }
70
+
71
+
72
+ Future <void > cancelAllNotifications () async {
73
+ try {
74
+ FlutterLocalNotificationsPlugin plugin = FlutterLocalNotificationsPlugin ();
75
+ await plugin.cancelAll ();
76
+ }catch (e){
77
+ print (e);
78
+ }
79
+ }
0 commit comments