Skip to content

Commit de3f71a

Browse files
committed
Added Notification Service
1 parent 3a3318d commit de3f71a

File tree

2 files changed

+97
-1
lines changed

2 files changed

+97
-1
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Flutter Core
22

3-
Projelerinizde kullanabileceğiniz çekirdek katman. [ Update: 15.05.2022 ]
3+
Projelerinizde kullanabileceğiniz çekirdek katman. [ Update: 21.05.2022 ]
44

55
#
66

@@ -39,6 +39,8 @@ NOT: Gerekli kütüphaneler yüklü değilse hata alabilirsiniz.
3939
- hive
4040
- hive_flutter
4141
- shared_preferences
42+
- Other
43+
- awesome_notifications
4244

4345
#
4446

@@ -92,3 +94,9 @@ QR oluşturmak veya qr okumak için kullanabilirsiniz.
9294
- #### [shared_preferences](https://github.com/cihatyalman/flutter_core/tree/master/lib/core/shared_preferences_service)
9395

9496
#
97+
98+
### Bildirim Servisi:
99+
100+
- #### [notification_service](https://github.com/cihatyalman/flutter_core/tree/master/lib/core/notification_service)
101+
102+
#
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Documents and Integration
2+
// https://pub.dev/packages/awesome_notifications
3+
4+
import 'package:awesome_notifications/awesome_notifications.dart';
5+
import 'package:flutter/material.dart';
6+
7+
final notificationService = NotificationService();
8+
9+
class NotificationService {
10+
final _noti = AwesomeNotifications();
11+
AwesomeNotifications get noti => _noti;
12+
13+
void init() {
14+
_noti.initialize(
15+
null,
16+
[
17+
NotificationChannel(
18+
channelKey: 'basic_channel',
19+
channelName: 'Basic Notifications',
20+
channelDescription: 'Notification Channel',
21+
defaultColor: Colors.teal, // primaryColor
22+
ledColor: Colors.white,
23+
channelShowBadge: true,
24+
importance: NotificationImportance.High,
25+
),
26+
],
27+
);
28+
29+
_noti.isNotificationAllowed().then((isAllowed) {
30+
// Edit
31+
if (!isAllowed) {
32+
_noti.requestPermissionToSendNotifications();
33+
} else {
34+
listen();
35+
}
36+
});
37+
}
38+
39+
void listen() {
40+
// Edit
41+
_noti
42+
..actionStream.listen((event) {
43+
print("[C_notiListenAction]: $event");
44+
// if (event.buttonKeyPressed == "btn1") {
45+
// print("[C_btn1]: Button 1 Clicked");
46+
// } else if (event.buttonKeyPressed == "btn2") {
47+
// print("[C_btn2]: Button 2 Clicked");
48+
// }
49+
})
50+
..dismissedStream.listen((event) {
51+
print("[C_notiListenDismissed]: $event");
52+
});
53+
}
54+
55+
int create({
56+
int? id,
57+
String? title,
58+
required String? body,
59+
String? groupKey,
60+
NotificationLayout? layout,
61+
String? largeIcon,
62+
String? bigPicture,
63+
Color? color,
64+
List<NotificationActionButton>? buttons,
65+
DateTime? showDate,
66+
}) {
67+
final _id = id ?? DateTime.now().millisecondsSinceEpoch.remainder(100000);
68+
_noti.createNotification(
69+
content: NotificationContent(
70+
channelKey: 'basic_channel',
71+
id: _id,
72+
title: title,
73+
body: body,
74+
groupKey: groupKey,
75+
color: color,
76+
largeIcon: largeIcon,
77+
bigPicture: bigPicture,
78+
notificationLayout:
79+
bigPicture != null ? NotificationLayout.BigPicture : layout,
80+
),
81+
actionButtons: buttons,
82+
schedule: showDate == null
83+
? null
84+
: NotificationCalendar.fromDate(date: showDate),
85+
);
86+
return _id;
87+
}
88+
}

0 commit comments

Comments
 (0)