@@ -13,27 +13,27 @@ class Courier {
1313 isDebugging = kDebugMode;
1414
1515 // Set the default iOS presentation options
16- iOSForegroundNotificationPresentationOptions =
17- _iOSForegroundNotificationPresentationOptions;
16+ iOSForegroundNotificationPresentationOptions = _iOSForegroundNotificationPresentationOptions;
1817
1918 // Register listeners for when the native system receives messages
2019 CourierFlutterEventsPlatform .instance.registerMessagingListeners (
21- onPushNotificationDelivered: (message) =>
22- _onPushNotificationDelivered? .call (message),
23- onPushNotificationClicked: (message) =>
24- _onPushNotificationClicked? .call (message),
25- onLogPosted: (log) =>
26- {/* Empty for now. Flutter will automatically print to console */ },
20+ onPushNotificationDelivered: (message) => _onPushNotificationDelivered? .call (message),
21+ onPushNotificationClicked: (message) => _onPushNotificationClicked? .call (message),
22+ onLogPosted: (log) => {
23+ /* Empty for now. Flutter will automatically print to console */
24+ },
2725 );
2826 }
2927
3028 // Singleton
3129 static Courier ? _instance;
30+
3231 static Courier get shared => _instance ?? = Courier ._();
3332
3433 /// Called if set and a push notification is delivered while the app
3534 /// Is in the foreground on iOS and "background" / foreground on Android
3635 Function (dynamic message)? _onPushNotificationDelivered;
36+
3737 set onPushNotificationDelivered (Function (dynamic message)? listener) {
3838 _onPushNotificationDelivered = listener;
3939 }
@@ -42,6 +42,7 @@ class Courier {
4242 /// Will automatically get called the first time your app starts
4343 /// and the user clicked on a push notification to launch your app
4444 Function (dynamic message)? _onPushNotificationClicked;
45+
4546 set onPushNotificationClicked (Function (dynamic message)? listener) {
4647 _onPushNotificationClicked = listener;
4748 CourierFlutterEventsPlatform .instance.getClickedNotification ();
@@ -50,7 +51,9 @@ class Courier {
5051 /// Allows you to show or hide Courier Native SDK debugging logs
5152 /// You likely want this to match your development environment debugging mode
5253 bool _isDebugging = kDebugMode;
54+
5355 bool get isDebugging => _isDebugging;
56+
5457 set isDebugging (bool isDebugging) {
5558 CourierFlutterCorePlatform .instance.isDebugging (isDebugging);
5659 _isDebugging = isDebugging;
@@ -60,16 +63,12 @@ class Courier {
6063 /// showing a push notification when it is received while the app is in the foreground.
6164 /// This will not have an affect on any other platform
6265 /// If you do not not want a system push to appear, pass []
66+ List <iOSNotificationPresentationOption> _iOSForegroundNotificationPresentationOptions = iOSNotificationPresentationOption.values;
67+
6368 List <iOSNotificationPresentationOption>
64- _iOSForegroundNotificationPresentationOptions =
65- iOSNotificationPresentationOption.values;
66- List <iOSNotificationPresentationOption>
67- get iOSForegroundNotificationPresentationOptions =>
68- _iOSForegroundNotificationPresentationOptions;
69- set iOSForegroundNotificationPresentationOptions (
70- List <iOSNotificationPresentationOption> options) {
71- CourierFlutterEventsPlatform .instance
72- .iOSForegroundPresentationOptions (options);
69+ get iOSForegroundNotificationPresentationOptions => _iOSForegroundNotificationPresentationOptions;
70+ set iOSForegroundNotificationPresentationOptions (List <iOSNotificationPresentationOption> options) {
71+ CourierFlutterEventsPlatform .instance.iOSForegroundPresentationOptions (options);
7372 _iOSForegroundNotificationPresentationOptions = options;
7473 }
7574
@@ -79,14 +78,12 @@ class Courier {
7978 /// Returns the currently stored apns token in the native SDK
8079 /// If you sign out, this value may still be set so that you can
8180 /// pass it to the next signed in userId
82- Future <String ?> get apnsToken =>
83- CourierFlutterCorePlatform .instance.apnsToken ();
81+ Future <String ?> get apnsToken => CourierFlutterCorePlatform .instance.apnsToken ();
8482
8583 /// Returns the currently stored fcm token in the native SDK
8684 /// If you sign out, this value may still be set so that you can
8785 /// pass it to the next signed in userId
88- Future <String ?> get fcmToken =>
89- CourierFlutterCorePlatform .instance.fcmToken ();
86+ Future <String ?> get fcmToken => CourierFlutterCorePlatform .instance.fcmToken ();
9087
9188 /// Sets the current FCM token in Courier Token Management
9289 /// Mostly used for handling the iOS Firebase SDK
@@ -114,29 +111,29 @@ class Courier {
114111 /// You should call this where it makes the most sense for the user experience you are building
115112 /// Android does NOT support this feature yet due to Android AppCompatActivity limitations
116113 Future <NotificationPermissionStatus > requestNotificationPermission () async {
117- final status = await CourierFlutterEventsPlatform .instance
118- .requestNotificationPermission ();
114+ final status = await CourierFlutterEventsPlatform .instance.requestNotificationPermission ();
119115 return status.permissionStatus;
120116 }
121117
122118 /// Returns the current push notification permission status
123119 /// Does not present a popup dialog to your user
124120 Future <NotificationPermissionStatus > getNotificationPermissionStatus () async {
125- final status = await CourierFlutterEventsPlatform .instance
126- .getNotificationPermissionStatus ();
121+ final status = await CourierFlutterEventsPlatform .instance.getNotificationPermissionStatus ();
127122 return status.permissionStatus;
128123 }
129124
130125 /// Sends a push notification to the provider your would like
131126 /// This is used to test your integration
132127 /// For more info: https://www.courier.com/docs/reference/send/message/
133- Future <String > sendPush (
134- {required String authKey,
135- required String userId,
136- required String title,
137- required String body,
138- required List <CourierProvider > providers}) {
139- return CourierFlutterCorePlatform .instance
140- .sendPush (authKey, userId, title, body, providers);
128+ Future <String > sendPush ({required String authKey, required String userId, required String title, required String body, required List <CourierProvider > providers}) {
129+ return CourierFlutterCorePlatform .instance.sendPush (authKey, userId, title, body, providers);
141130 }
131+
132+ /// Show a log to the console
133+ static void log (String message) {
134+ if (Courier .shared._isDebugging) {
135+ print (message);
136+ }
137+ }
138+
142139}
0 commit comments