Skip to content

feat: Add new new push notification interface ParseNotification for managing push notifications #949

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 19 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## [6.0.0](https://github.com/parse-community/Parse-SDK-Flutter/compare/flutter-5.1.2...flutter-6.0.0) (2023-08-06)

### BREAKING CHANGES

* 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))

### Features

* Add new new push notification interface `ParseNotification` for managing push notifications ([#949](https://github.com/parse-community/Parse-SDK-Flutter/pull/949))

## [5.1.2](https://github.com/parse-community/Parse-SDK-Flutter/compare/flutter-5.1.1...flutter-5.1.2) (2023-07-11)

### Bug Fixes
Expand Down
2 changes: 0 additions & 2 deletions packages/flutter/lib/parse_server_sdk_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ library flutter_parse_sdk_flutter;
import 'dart:convert';
import 'dart:async';
import 'dart:io';
import 'dart:math';
import 'dart:ui';
import 'package:path/path.dart' as path;
import 'package:connectivity_plus/connectivity_plus.dart';
Expand All @@ -15,7 +14,6 @@ import 'package:parse_server_sdk_flutter/src/storage/core_store_directory_io.dar
if (dart.library.html) 'package:parse_server_sdk_flutter/src/storage/core_store_directory_web.dart';
import 'package:sembast/sembast.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';

export 'package:parse_server_sdk/parse_server_sdk.dart'
hide Parse, CoreStoreSembastImp;
Expand Down
65 changes: 3 additions & 62 deletions packages/flutter/lib/src/notification/parse_notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,12 @@ part of flutter_parse_sdk_flutter;

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

final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();

AndroidInitializationSettings? _androidNotificationSettings;
DarwinInitializationSettings? _iOSNotificationSettings;
DarwinInitializationSettings? _macOSNotificationSettings;
LinuxInitializationSettings? _linuxNotificationSettings;

factory ParseNotification() {
return instance;
}

ParseNotification._internal() {
_initialize();
}

setNotificationSettings(
{AndroidInitializationSettings? androidNotificationSettings,
DarwinInitializationSettings? iOSNotificationSettings,
DarwinInitializationSettings? macOSNotificationSettings,
LinuxInitializationSettings? linuxNotificationSettings}) {
_androidNotificationSettings = androidNotificationSettings;
_iOSNotificationSettings = iOSNotificationSettings;
_macOSNotificationSettings = macOSNotificationSettings;
_linuxNotificationSettings = linuxNotificationSettings;
}

/// Initialize notification helper
Future<void> _initialize() async {
InitializationSettings initializationSettings = InitializationSettings(
android: _androidNotificationSettings ??
const AndroidInitializationSettings('launch_background'),
iOS: _iOSNotificationSettings,
linux: _linuxNotificationSettings,
macOS: _macOSNotificationSettings);

AndroidNotificationChannel channel = AndroidNotificationChannel(
keyNotificationChannelName, // id
keyNotificationChannelName, // title
importance: Importance.max,
);

await _flutterLocalNotificationsPlugin.initialize(initializationSettings);

await _flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.createNotificationChannel(channel);
}
final void Function(String value) onShowNotification;

/// Show notification
void showNotification(title) {
_flutterLocalNotificationsPlugin.show(
Random().nextInt(1000),
title,
null,
NotificationDetails(
android: AndroidNotificationDetails(
keyNotificationChannelName,
keyNotificationChannelName,
// other properties...
),
));
onShowNotification.call(title);
}
}
16 changes: 5 additions & 11 deletions packages/flutter/lib/src/push/parse_push.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class ParsePush {
static String keyType = "gcm";
static String keyPushType = 'pushType';

late ParseNotification _parseNotification;

factory ParsePush() {
return instance;
}
Expand All @@ -17,17 +19,9 @@ class ParsePush {
Future<void> initialize(
firebaseMessaging, {
String? vapidKey,
AndroidInitializationSettings? androidNotificationSettings,
DarwinInitializationSettings? iOSNotificationSettings,
DarwinInitializationSettings? macOSNotificationSettings,
LinuxInitializationSettings? linuxNotificationSettings,
required ParseNotification parseNotification,
}) async {
// Parse Notification settings
ParseNotification.instance.setNotificationSettings(
androidNotificationSettings: androidNotificationSettings,
iOSNotificationSettings: iOSNotificationSettings,
linuxNotificationSettings: linuxNotificationSettings,
macOSNotificationSettings: macOSNotificationSettings);
_parseNotification = parseNotification;

// Get Google Cloud Messaging (GCM) token
firebaseMessaging
Expand Down Expand Up @@ -69,7 +63,7 @@ class ParsePush {

if (data != null) {
// Show push notification
ParseNotification.instance.showNotification(data["alert"]);
_parseNotification.showNotification(data["alert"]);
}
}

Expand Down
3 changes: 1 addition & 2 deletions packages/flutter/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: parse_server_sdk_flutter
description: The Flutter SDK to connect to Parse Server. Build your apps faster with Parse Platform, the complete application stack.
version: 5.1.2
version: 6.0.0
homepage: https://github.com/parse-community/Parse-SDK-Flutter

environment:
Expand All @@ -26,7 +26,6 @@ dependencies:
# Utils
path_provider: ^2.0.15
package_info_plus: ^4.0.2
flutter_local_notifications: ^14.1.1
path: ^1.8.2

dev_dependencies:
Expand Down