Skip to content

Commit 9b129df

Browse files
committed
Reflex handler
1 parent 73f539b commit 9b129df

File tree

11 files changed

+87
-10
lines changed

11 files changed

+87
-10
lines changed

android/.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package com.devsonflutter.reflex;public class EventCallHandler {
2+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package com.devsonflutter.reflex.notification;public class NotificationListener {
2+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package com.devsonflutter.reflex.notification;public class NotificationReceiver {
2+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package com.devsonflutter.reflex.notification;public class ReflexNotification {
2+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package com.devsonflutter.reflex.permission;public class NotificationPermission {
2+
}

lib/reflex.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ for more details.
1010

1111
import 'dart:async';
1212

13+
import 'package:reflex/src/helper/events/notification_event.dart';
1314
import 'package:reflex/src/platform/reflex_platform.dart';
1415

1516
export 'package:reflex/src/helper/helper.dart';
1617

1718
class Reflex {
1819
/// [notificationStream] returns stream of notifications.
19-
Stream<String> get notificationStream {
20+
Stream<NotificationEvent>? get notificationStream {
2021
return ReflexPlatform.instance.notificationStream;
2122
}
2223
}

lib/src/handler/reflex_handler.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ for more details.
1111
import 'dart:io';
1212

1313
import 'package:flutter/services.dart';
14+
import 'package:reflex/src/helper/events/notification_event.dart';
1415
import 'package:reflex/src/helper/exception/reflex_exception.dart';
1516
import 'package:reflex/src/platform/reflex_platform.dart';
1617

@@ -22,16 +23,17 @@ class ReflexHandler extends ReflexPlatform {
2223
// MethodChannel get methodChannel => _methodChannel;
2324
EventChannel get eventChannel => _eventChannel;
2425

25-
Stream<String>? _notificationStream;
26+
Stream<NotificationEvent>? _notificationStream;
2627

2728
@override
28-
Stream<String> get notificationStream {
29+
Stream<NotificationEvent>? get notificationStream {
2930
if (Platform.isAndroid) {
3031
_notificationStream ??=
31-
_eventChannel.receiveBroadcastStream().map<String>((event) => event);
32-
return _notificationStream!;
32+
_eventChannel.receiveBroadcastStream().map<NotificationEvent>(
33+
(event) => NotificationEvent.getNotificationEventFromMap(event),
34+
);
35+
return _notificationStream;
3336
}
34-
throw ReflexException(
35-
'Reflex.notificationStream is only supported on Android.');
37+
throw ReflexException('notificationStream is only supported on Android!');
3638
}
3739
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
3+
Copyright (c) 2022 DevsOnFlutter (Devs On Flutter)
4+
All rights reserved.
5+
6+
The plugin is governed by the BSD-3-clause License. Please see the LICENSE file
7+
for more details.
8+
9+
*/
10+
11+
class NotificationEvent {
12+
NotificationEvent({
13+
this.packageName,
14+
this.title,
15+
this.message,
16+
this.timeStamp,
17+
});
18+
19+
/// The package name of the app that sent the notification.
20+
String? packageName;
21+
22+
/// Notification Title
23+
String? title;
24+
25+
/// Notification Message
26+
String? message;
27+
28+
/// The time stamp of the notification.
29+
DateTime? timeStamp;
30+
31+
factory NotificationEvent.fromMap(Map<dynamic, dynamic> map) {
32+
DateTime time = DateTime.now();
33+
String? name = map['packageName'];
34+
String? message = map['message'];
35+
String? title = map['title'];
36+
37+
return NotificationEvent(
38+
packageName: name,
39+
title: title,
40+
message: message,
41+
timeStamp: time,
42+
);
43+
}
44+
45+
static NotificationEvent getNotificationEventFromMap(dynamic data) {
46+
return NotificationEvent.fromMap(data);
47+
}
48+
49+
@override
50+
String toString() {
51+
return '''$runtimeType
52+
Package Name: $packageName,
53+
Title: $title,
54+
Message: $message,
55+
Timestamp: $timeStamp''';
56+
}
57+
}

lib/src/helper/helper.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ for more details.
99
*/
1010

1111
export 'exception/reflex_exception.dart';
12+
export 'events/notification_event.dart';

0 commit comments

Comments
 (0)