diff --git a/packages/flutter/CHANGELOG.md b/packages/flutter/CHANGELOG.md index d0d5dd32..e0524f15 100644 --- a/packages/flutter/CHANGELOG.md +++ b/packages/flutter/CHANGELOG.md @@ -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 diff --git a/packages/flutter/lib/parse_server_sdk_flutter.dart b/packages/flutter/lib/parse_server_sdk_flutter.dart index ead9124f..33e4d8e7 100644 --- a/packages/flutter/lib/parse_server_sdk_flutter.dart +++ b/packages/flutter/lib/parse_server_sdk_flutter.dart @@ -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'; @@ -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; diff --git a/packages/flutter/lib/src/notification/parse_notification.dart b/packages/flutter/lib/src/notification/parse_notification.dart index 66129b04..92a2ec69 100644 --- a/packages/flutter/lib/src/notification/parse_notification.dart +++ b/packages/flutter/lib/src/notification/parse_notification.dart @@ -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 _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); } } diff --git a/packages/flutter/lib/src/push/parse_push.dart b/packages/flutter/lib/src/push/parse_push.dart index d4f516d6..7147f24e 100644 --- a/packages/flutter/lib/src/push/parse_push.dart +++ b/packages/flutter/lib/src/push/parse_push.dart @@ -7,6 +7,8 @@ class ParsePush { static String keyType = "gcm"; static String keyPushType = 'pushType'; + late ParseNotification _parseNotification; + factory ParsePush() { return instance; } @@ -17,17 +19,9 @@ class ParsePush { Future 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 @@ -69,7 +63,7 @@ class ParsePush { if (data != null) { // Show push notification - ParseNotification.instance.showNotification(data["alert"]); + _parseNotification.showNotification(data["alert"]); } } diff --git a/packages/flutter/pubspec.yaml b/packages/flutter/pubspec.yaml index 3f43eccf..183fd8f8 100644 --- a/packages/flutter/pubspec.yaml +++ b/packages/flutter/pubspec.yaml @@ -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: @@ -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: