Skip to content

Commit a2fb099

Browse files
authored
feat: Add new new push notification interface ParseNotification for managing push notifications (#949)
1 parent aefc84e commit a2fb099

File tree

5 files changed

+19
-77
lines changed

5 files changed

+19
-77
lines changed

packages/flutter/CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## [6.0.0](https://github.com/parse-community/Parse-SDK-Flutter/compare/flutter-5.1.2...flutter-6.0.0) (2023-08-06)
2+
3+
### BREAKING CHANGES
4+
5+
* The push notification library flutter_local_notifications is replaced with the new push notification interface `ParseNotification` ([#949](https://github.com/parse-community/Parse-SDK-Flutter/pull/949))
6+
7+
### Features
8+
9+
* Add new new push notification interface `ParseNotification` for managing push notifications ([#949](https://github.com/parse-community/Parse-SDK-Flutter/pull/949))
10+
111
## [5.1.2](https://github.com/parse-community/Parse-SDK-Flutter/compare/flutter-5.1.1...flutter-5.1.2) (2023-07-11)
212

313
### Bug Fixes

packages/flutter/lib/parse_server_sdk_flutter.dart

-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ library flutter_parse_sdk_flutter;
33
import 'dart:convert';
44
import 'dart:async';
55
import 'dart:io';
6-
import 'dart:math';
76
import 'dart:ui';
87
import 'package:path/path.dart' as path;
98
import 'package:connectivity_plus/connectivity_plus.dart';
@@ -15,7 +14,6 @@ import 'package:parse_server_sdk_flutter/src/storage/core_store_directory_io.dar
1514
if (dart.library.html) 'package:parse_server_sdk_flutter/src/storage/core_store_directory_web.dart';
1615
import 'package:sembast/sembast.dart';
1716
import 'package:shared_preferences/shared_preferences.dart';
18-
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
1917

2018
export 'package:parse_server_sdk/parse_server_sdk.dart'
2119
hide Parse, CoreStoreSembastImp;

packages/flutter/lib/src/notification/parse_notification.dart

+3-62
Original file line numberDiff line numberDiff line change
@@ -2,71 +2,12 @@ part of flutter_parse_sdk_flutter;
22

33
/// A class that provides a mechanism for showing system notifications in the app.
44
class ParseNotification {
5-
static final ParseNotification instance = ParseNotification._internal();
6-
static String keyNotificationChannelName = "parse";
5+
ParseNotification({required this.onShowNotification});
76

8-
final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
9-
FlutterLocalNotificationsPlugin();
10-
11-
AndroidInitializationSettings? _androidNotificationSettings;
12-
DarwinInitializationSettings? _iOSNotificationSettings;
13-
DarwinInitializationSettings? _macOSNotificationSettings;
14-
LinuxInitializationSettings? _linuxNotificationSettings;
15-
16-
factory ParseNotification() {
17-
return instance;
18-
}
19-
20-
ParseNotification._internal() {
21-
_initialize();
22-
}
23-
24-
setNotificationSettings(
25-
{AndroidInitializationSettings? androidNotificationSettings,
26-
DarwinInitializationSettings? iOSNotificationSettings,
27-
DarwinInitializationSettings? macOSNotificationSettings,
28-
LinuxInitializationSettings? linuxNotificationSettings}) {
29-
_androidNotificationSettings = androidNotificationSettings;
30-
_iOSNotificationSettings = iOSNotificationSettings;
31-
_macOSNotificationSettings = macOSNotificationSettings;
32-
_linuxNotificationSettings = linuxNotificationSettings;
33-
}
34-
35-
/// Initialize notification helper
36-
Future<void> _initialize() async {
37-
InitializationSettings initializationSettings = InitializationSettings(
38-
android: _androidNotificationSettings ??
39-
const AndroidInitializationSettings('launch_background'),
40-
iOS: _iOSNotificationSettings,
41-
linux: _linuxNotificationSettings,
42-
macOS: _macOSNotificationSettings);
43-
44-
AndroidNotificationChannel channel = AndroidNotificationChannel(
45-
keyNotificationChannelName, // id
46-
keyNotificationChannelName, // title
47-
importance: Importance.max,
48-
);
49-
50-
await _flutterLocalNotificationsPlugin.initialize(initializationSettings);
51-
52-
await _flutterLocalNotificationsPlugin
53-
.resolvePlatformSpecificImplementation<
54-
AndroidFlutterLocalNotificationsPlugin>()
55-
?.createNotificationChannel(channel);
56-
}
7+
final void Function(String value) onShowNotification;
578

589
/// Show notification
5910
void showNotification(title) {
60-
_flutterLocalNotificationsPlugin.show(
61-
Random().nextInt(1000),
62-
title,
63-
null,
64-
NotificationDetails(
65-
android: AndroidNotificationDetails(
66-
keyNotificationChannelName,
67-
keyNotificationChannelName,
68-
// other properties...
69-
),
70-
));
11+
onShowNotification.call(title);
7112
}
7213
}

packages/flutter/lib/src/push/parse_push.dart

+5-11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ class ParsePush {
77
static String keyType = "gcm";
88
static String keyPushType = 'pushType';
99

10+
late ParseNotification _parseNotification;
11+
1012
factory ParsePush() {
1113
return instance;
1214
}
@@ -17,17 +19,9 @@ class ParsePush {
1719
Future<void> initialize(
1820
firebaseMessaging, {
1921
String? vapidKey,
20-
AndroidInitializationSettings? androidNotificationSettings,
21-
DarwinInitializationSettings? iOSNotificationSettings,
22-
DarwinInitializationSettings? macOSNotificationSettings,
23-
LinuxInitializationSettings? linuxNotificationSettings,
22+
required ParseNotification parseNotification,
2423
}) async {
25-
// Parse Notification settings
26-
ParseNotification.instance.setNotificationSettings(
27-
androidNotificationSettings: androidNotificationSettings,
28-
iOSNotificationSettings: iOSNotificationSettings,
29-
linuxNotificationSettings: linuxNotificationSettings,
30-
macOSNotificationSettings: macOSNotificationSettings);
24+
_parseNotification = parseNotification;
3125

3226
// Get Google Cloud Messaging (GCM) token
3327
firebaseMessaging
@@ -69,7 +63,7 @@ class ParsePush {
6963

7064
if (data != null) {
7165
// Show push notification
72-
ParseNotification.instance.showNotification(data["alert"]);
66+
_parseNotification.showNotification(data["alert"]);
7367
}
7468
}
7569

packages/flutter/pubspec.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: parse_server_sdk_flutter
22
description: The Flutter SDK to connect to Parse Server. Build your apps faster with Parse Platform, the complete application stack.
3-
version: 5.1.2
3+
version: 6.0.0
44
homepage: https://github.com/parse-community/Parse-SDK-Flutter
55

66
environment:
@@ -26,7 +26,6 @@ dependencies:
2626
# Utils
2727
path_provider: ^2.0.15
2828
package_info_plus: ^4.0.2
29-
flutter_local_notifications: ^14.1.1
3029
path: ^1.8.2
3130

3231
dev_dependencies:

0 commit comments

Comments
 (0)