Skip to content

Commit fc6dd88

Browse files
committed
feat: added notification accessors
1 parent b7d962b commit fc6dd88

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

lib/js_notifications_web.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,28 @@ class JsNotificationsWeb extends JsNotificationsPlatform {
158158
_tapStream ??= StreamController<NotificationActionResult>.broadcast();
159159
return _tapStream!.stream;
160160
}
161+
162+
@override
163+
Future<List<String>> getNotificationTags() async {
164+
return _notifications.keys.toList();
165+
}
166+
167+
@override
168+
Future<interop.JSNotification?> getNotification(String tag) async {
169+
return _notifications[tag];
170+
}
171+
172+
@override
173+
Future<List<interop.JSNotification>> getAllNotifications() async {
174+
return _notifications.values.toList();
175+
}
176+
177+
void _addNotification(String id, interop.JSNotification notification) {
178+
_notifications[id] = notification;
179+
}
180+
181+
@override
182+
Future<void> dispose() async {
183+
await _dismissSubscription.cancel();
184+
}
161185
}

lib/method_channel/js_notifications_method_channel.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,28 @@ class MethodChannelJsNotifications extends JsNotificationsPlatform {
7575
set scopeUrl(String value) {
7676
// TODO: implement scopeUrl
7777
}
78+
79+
@override
80+
Future<List<interop.JSNotification>> getAllNotifications() {
81+
// TODO: implement getAllNotifications
82+
throw UnimplementedError();
83+
}
84+
85+
@override
86+
Future<interop.JSNotification?> getNotification(String tag) {
87+
// TODO: implement getNotification
88+
throw UnimplementedError();
89+
}
90+
91+
@override
92+
Future<List<String>> getNotificationTags() {
93+
// TODO: implement getNotificationTags
94+
throw UnimplementedError();
95+
}
96+
97+
@override
98+
Future<void> dispose() {
99+
// TODO: implement dispose
100+
throw UnimplementedError();
101+
}
78102
}

lib/platform_interface/js_notifications_platform_interface.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ abstract class JsNotificationsPlatform extends PlatformInterface {
7878
/// Send action to service worker
7979
Future<void> sendAction(Map<String, dynamic> data, {String? id});
8080

81+
/// Get all notification tags
82+
Future<List<String>> getNotificationTags();
83+
84+
/// Get notification by tag
85+
Future<interop.JSNotification?> getNotification(String tag);
86+
87+
/// Get all notifications
88+
Future<List<interop.JSNotification>> getAllNotifications();
89+
8190
/// Stream broadcasting notification click events with associated data & action
8291
Stream<NotificationActionResult> get actionStream;
8392

@@ -86,4 +95,6 @@ abstract class JsNotificationsPlatform extends PlatformInterface {
8695

8796
/// Stream broadcasting notification tap events with associated data
8897
Stream<NotificationActionResult> get tapStream;
98+
99+
Future<void> dispose();
89100
}

0 commit comments

Comments
 (0)