diff --git a/CHANGELOG.md b/CHANGELOG.md index b23aafd..66594f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [4.0.0] - 14 August 2024 + +* Fix overflow issue with long text in notification +* Fix new notification only sending to the person that triggered the notification +* Added `onNotificationTap` to a notification + ## [2.0.0] - 6 June 2024 * Rework design for notification center diff --git a/packages/flutter_notification_center/lib/src/models/notification_config.dart b/packages/flutter_notification_center/lib/src/models/notification_config.dart index 705c609..6e3214e 100644 --- a/packages/flutter_notification_center/lib/src/models/notification_config.dart +++ b/packages/flutter_notification_center/lib/src/models/notification_config.dart @@ -19,6 +19,7 @@ class NotificationConfig { this.bellStyle = const AnimatedNotificationBellStyle(), this.pinnedIconColor = Colors.black, this.emptyNotificationsBuilder, + this.onNotificationTap, }); /// The notification service to use for delivering notifications. @@ -46,4 +47,6 @@ class NotificationConfig { /// A builder function to display when there are no notifications. final Widget Function()? emptyNotificationsBuilder; + + final Function(NotificationModel)? onNotificationTap; } diff --git a/packages/flutter_notification_center/lib/src/notification_center.dart b/packages/flutter_notification_center/lib/src/notification_center.dart index 60ab2a6..3180d9f 100644 --- a/packages/flutter_notification_center/lib/src/notification_center.dart +++ b/packages/flutter_notification_center/lib/src/notification_center.dart @@ -94,12 +94,18 @@ class NotificationCenterState extends State { var notification = snapshot.data![index]; return notification.isPinned ? GestureDetector( - onTap: () async => _navigateToNotificationDetail( - context, - notification, - widget.config.service, - widget.config.translations, - ), + onTap: () async { + if (widget.config.onNotificationTap != null) { + widget.config.onNotificationTap!.call(notification); + } else { + await _navigateToNotificationDetail( + context, + notification, + widget.config.service, + widget.config.translations, + ); + } + }, child: Dismissible( key: Key("${notification.id}_pinned"), onDismissed: (direction) async { @@ -170,12 +176,18 @@ class NotificationCenterState extends State { ), ) : GestureDetector( - onTap: () async => _navigateToNotificationDetail( - context, - notification, - widget.config.service, - widget.config.translations, - ), + onTap: () async { + if (widget.config.onNotificationTap != null) { + widget.config.onNotificationTap!.call(notification); + } else { + await _navigateToNotificationDetail( + context, + notification, + widget.config.service, + widget.config.translations, + ); + } + }, child: Dismissible( key: Key(notification.id), onDismissed: (direction) async { @@ -274,16 +286,20 @@ Widget _notificationItem( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( + crossAxisAlignment: CrossAxisAlignment.start, children: [ if (!notification.isPinned) ...[ if (!notification.isRead) ...[ const SizedBox( width: 8, ), - const Icon( - Icons.circle_rounded, - color: Colors.black, - size: 8, + const Padding( + padding: EdgeInsets.only(top: 8), + child: Icon( + Icons.circle_rounded, + color: Colors.black, + size: 8, + ), ), const SizedBox( width: 8, @@ -305,11 +321,13 @@ Widget _notificationItem( width: 8, ), ], - Text( - notification.title, - style: notification.isRead && !notification.isPinned - ? theme.textTheme.bodyMedium - : theme.textTheme.titleMedium, + Flexible( + child: Text( + notification.title, + style: notification.isRead && !notification.isPinned + ? theme.textTheme.bodyMedium + : theme.textTheme.titleMedium, + ), ), ], ), diff --git a/packages/flutter_notification_center/lib/src/services/notification_service.dart b/packages/flutter_notification_center/lib/src/services/notification_service.dart index 140057c..397b31a 100644 --- a/packages/flutter_notification_center/lib/src/services/notification_service.dart +++ b/packages/flutter_notification_center/lib/src/services/notification_service.dart @@ -27,7 +27,8 @@ abstract class NotificationService with ChangeNotifier { /// Pushes a notification to the service. Future pushNotification( - NotificationModel notification, [ + NotificationModel notification, + List recipientIds, [ Function(NotificationModel model)? onNewNotification, ]); diff --git a/packages/flutter_notification_center/pubspec.yaml b/packages/flutter_notification_center/pubspec.yaml index f9f0a6e..66c1b4b 100644 --- a/packages/flutter_notification_center/pubspec.yaml +++ b/packages/flutter_notification_center/pubspec.yaml @@ -1,7 +1,7 @@ name: flutter_notification_center description: "A Flutter package for displaying notifications in a notification center." publish_to: "none" -version: 3.0.1 +version: 4.0.0 environment: sdk: ">=3.3.2 <4.0.0" diff --git a/packages/flutter_notification_center_firebase/lib/src/services/firebase_notification_service.dart b/packages/flutter_notification_center_firebase/lib/src/services/firebase_notification_service.dart index 45763fc..1cbc6ed 100644 --- a/packages/flutter_notification_center_firebase/lib/src/services/firebase_notification_service.dart +++ b/packages/flutter_notification_center_firebase/lib/src/services/firebase_notification_service.dart @@ -42,7 +42,8 @@ class FirebaseNotificationService @override Future pushNotification( - NotificationModel notification, [ + NotificationModel notification, + List recipientIds, [ Function(NotificationModel model)? onNewNotification, ]) async { try { @@ -53,24 +54,30 @@ class FirebaseNotificationService return; } - CollectionReference notifications = - FirebaseFirestore.instanceFor(app: _firebaseApp) - .collection(activeNotificationsCollection) - .doc(userId) - .collection(activeNotificationsCollection); + for (var recipientId in recipientIds) { + CollectionReference notifications = + FirebaseFirestore.instanceFor(app: _firebaseApp) + .collection(activeNotificationsCollection) + .doc(recipientId) + .collection(activeNotificationsCollection); - var currentDateTime = DateTime.now(); - notification.dateTimePushed = currentDateTime; - var notificationMap = notification.toMap(); - await notifications.doc(notification.id).set(notificationMap); + var currentDateTime = DateTime.now(); + notification.dateTimePushed = currentDateTime; + var notificationMap = notification.toMap(); + await notifications.doc(notification.id).set(notificationMap); + } + if (recipientIds.contains(userId)) { + listOfActiveNotifications = [ + ...listOfActiveNotifications, + notification, + ]; - listOfActiveNotifications = [...listOfActiveNotifications, notification]; - - //Show popup with notification conte - if (onNewNotification != null) { - onNewNotification(notification); - } else { - newNotificationCallback(notification); + //Show popup with notification conte + if (onNewNotification != null) { + onNewNotification(notification); + } else { + newNotificationCallback(notification); + } } notifyListeners(); @@ -364,7 +371,11 @@ class FirebaseNotificationService for (var notification in plannedNotifications) { if (notification.scheduledFor!.isBefore(currentTime) || notification.scheduledFor!.isAtSameMomentAs(currentTime)) { - await pushNotification(notification, newNotificationCallback); + await pushNotification( + notification, + [userId], + newNotificationCallback, + ); await deletePlannedNotification(notification); diff --git a/packages/flutter_notification_center_firebase/pubspec.yaml b/packages/flutter_notification_center_firebase/pubspec.yaml index ae7b1b2..4f60b98 100644 --- a/packages/flutter_notification_center_firebase/pubspec.yaml +++ b/packages/flutter_notification_center_firebase/pubspec.yaml @@ -1,7 +1,7 @@ name: flutter_notification_center_firebase description: "A new Flutter project." publish_to: "none" -version: 3.0.0 +version: 4.0.0 environment: sdk: ">=2.18.0 <3.0.0" @@ -21,7 +21,7 @@ dependencies: flutter_notification_center: git: url: https://github.com/Iconica-Development/flutter_notification_center - ref: 3.0.1 + ref: 4.0.0 path: packages/flutter_notification_center dev_dependencies: