@@ -2,15 +2,18 @@ import 'dart:async';
2
2
import 'package:flutter/services.dart' ;
3
3
import 'package:onesignal_flutter/src/subscription.dart' ;
4
4
5
+ typedef void OnPushSubscriptionChangeObserver (
6
+ OSPushSubscriptionChangedState stateChanges);
7
+
5
8
class OneSignalPushSubscription {
6
9
MethodChannel _channel = const MethodChannel ('OneSignal#pushsubscription' );
7
10
8
11
String ? _id;
9
12
String ? _token;
10
13
bool ? _optedIn;
11
14
12
- List <OneSignalPushSubscriptionObserver > _observers =
13
- < OneSignalPushSubscriptionObserver > [];
15
+ List <OnPushSubscriptionChangeObserver > _observers =
16
+ < OnPushSubscriptionChangeObserver > [];
14
17
// constructor method
15
18
OneSignalPushSubscription () {
16
19
this ._channel.setMethodCallHandler (_handleMethod);
@@ -49,12 +52,12 @@ class OneSignalPushSubscription {
49
52
/// The OSPushSubscriptionObserver.onOSPushSubscriptionChanged method will be fired on the passed-in
50
53
// object when the push subscription changes. This method returns the current OSPushSubscriptionState
51
54
// at the time of adding this observer.
52
- void addObserver (OneSignalPushSubscriptionObserver observer) {
55
+ void addObserver (OnPushSubscriptionChangeObserver observer) {
53
56
_observers.add (observer);
54
57
}
55
58
56
59
// Remove a push subscription observer that has been previously added.
57
- void removeObserver (OneSignalPushSubscriptionObserver observer) {
60
+ void removeObserver (OnPushSubscriptionChangeObserver observer) {
58
61
_observers.remove (observer);
59
62
}
60
63
@@ -81,12 +84,7 @@ class OneSignalPushSubscription {
81
84
this ._optedIn = stateChanges.current.optedIn;
82
85
83
86
for (var observer in _observers) {
84
- observer. onOSPushSubscriptionChange (stateChanges);
87
+ observer (stateChanges);
85
88
}
86
89
}
87
90
}
88
-
89
- class OneSignalPushSubscriptionObserver {
90
- void onOSPushSubscriptionChange (
91
- OSPushSubscriptionChangedState stateChanges) {}
92
- }
0 commit comments