Merge pull request #27 from Iconica-Development/bugfix/feedback_v2

fix: unread notification count, title style, onTap notification
This commit is contained in:
mike doornenbal 2024-09-05 11:33:34 +02:00 committed by GitHub
commit ddf2a2bbb3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 82 additions and 43 deletions

View file

@ -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 ## [2.0.0] - 6 June 2024
* Rework design for notification center * Rework design for notification center

View file

@ -19,6 +19,7 @@ class NotificationConfig {
this.bellStyle = const AnimatedNotificationBellStyle(), this.bellStyle = const AnimatedNotificationBellStyle(),
this.pinnedIconColor = Colors.black, this.pinnedIconColor = Colors.black,
this.emptyNotificationsBuilder, this.emptyNotificationsBuilder,
this.onNotificationTap,
}); });
/// The notification service to use for delivering notifications. /// The notification service to use for delivering notifications.
@ -46,4 +47,6 @@ class NotificationConfig {
/// A builder function to display when there are no notifications. /// A builder function to display when there are no notifications.
final Widget Function()? emptyNotificationsBuilder; final Widget Function()? emptyNotificationsBuilder;
final Function(NotificationModel)? onNotificationTap;
} }

View file

@ -94,12 +94,18 @@ class NotificationCenterState extends State<NotificationCenter> {
var notification = snapshot.data![index]; var notification = snapshot.data![index];
return notification.isPinned return notification.isPinned
? GestureDetector( ? GestureDetector(
onTap: () async => _navigateToNotificationDetail( onTap: () async {
if (widget.config.onNotificationTap != null) {
widget.config.onNotificationTap!.call(notification);
} else {
await _navigateToNotificationDetail(
context, context,
notification, notification,
widget.config.service, widget.config.service,
widget.config.translations, widget.config.translations,
), );
}
},
child: Dismissible( child: Dismissible(
key: Key("${notification.id}_pinned"), key: Key("${notification.id}_pinned"),
onDismissed: (direction) async { onDismissed: (direction) async {
@ -170,12 +176,18 @@ class NotificationCenterState extends State<NotificationCenter> {
), ),
) )
: GestureDetector( : GestureDetector(
onTap: () async => _navigateToNotificationDetail( onTap: () async {
if (widget.config.onNotificationTap != null) {
widget.config.onNotificationTap!.call(notification);
} else {
await _navigateToNotificationDetail(
context, context,
notification, notification,
widget.config.service, widget.config.service,
widget.config.translations, widget.config.translations,
), );
}
},
child: Dismissible( child: Dismissible(
key: Key(notification.id), key: Key(notification.id),
onDismissed: (direction) async { onDismissed: (direction) async {
@ -274,17 +286,21 @@ Widget _notificationItem(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Row( Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
if (!notification.isPinned) ...[ if (!notification.isPinned) ...[
if (!notification.isRead) ...[ if (!notification.isRead) ...[
const SizedBox( const SizedBox(
width: 8, width: 8,
), ),
const Icon( const Padding(
padding: EdgeInsets.only(top: 8),
child: Icon(
Icons.circle_rounded, Icons.circle_rounded,
color: Colors.black, color: Colors.black,
size: 8, size: 8,
), ),
),
const SizedBox( const SizedBox(
width: 8, width: 8,
), ),
@ -305,12 +321,14 @@ Widget _notificationItem(
width: 8, width: 8,
), ),
], ],
Text( Flexible(
child: Text(
notification.title, notification.title,
style: notification.isRead && !notification.isPinned style: notification.isRead && !notification.isPinned
? theme.textTheme.bodyMedium ? theme.textTheme.bodyMedium
: theme.textTheme.titleMedium, : theme.textTheme.titleMedium,
), ),
),
], ],
), ),
Text( Text(

View file

@ -27,7 +27,8 @@ abstract class NotificationService with ChangeNotifier {
/// Pushes a notification to the service. /// Pushes a notification to the service.
Future pushNotification( Future pushNotification(
NotificationModel notification, [ NotificationModel notification,
List<String> recipientIds, [
Function(NotificationModel model)? onNewNotification, Function(NotificationModel model)? onNewNotification,
]); ]);

View file

@ -1,7 +1,7 @@
name: flutter_notification_center name: flutter_notification_center
description: "A Flutter package for displaying notifications in a notification center." description: "A Flutter package for displaying notifications in a notification center."
publish_to: "none" publish_to: "none"
version: 3.0.1 version: 4.0.0
environment: environment:
sdk: ">=3.3.2 <4.0.0" sdk: ">=3.3.2 <4.0.0"

View file

@ -42,7 +42,8 @@ class FirebaseNotificationService
@override @override
Future<void> pushNotification( Future<void> pushNotification(
NotificationModel notification, [ NotificationModel notification,
List<String> recipientIds, [
Function(NotificationModel model)? onNewNotification, Function(NotificationModel model)? onNewNotification,
]) async { ]) async {
try { try {
@ -53,18 +54,23 @@ class FirebaseNotificationService
return; return;
} }
for (var recipientId in recipientIds) {
CollectionReference notifications = CollectionReference notifications =
FirebaseFirestore.instanceFor(app: _firebaseApp) FirebaseFirestore.instanceFor(app: _firebaseApp)
.collection(activeNotificationsCollection) .collection(activeNotificationsCollection)
.doc(userId) .doc(recipientId)
.collection(activeNotificationsCollection); .collection(activeNotificationsCollection);
var currentDateTime = DateTime.now(); var currentDateTime = DateTime.now();
notification.dateTimePushed = currentDateTime; notification.dateTimePushed = currentDateTime;
var notificationMap = notification.toMap(); var notificationMap = notification.toMap();
await notifications.doc(notification.id).set(notificationMap); await notifications.doc(notification.id).set(notificationMap);
}
listOfActiveNotifications = [...listOfActiveNotifications, notification]; if (recipientIds.contains(userId)) {
listOfActiveNotifications = [
...listOfActiveNotifications,
notification,
];
//Show popup with notification conte //Show popup with notification conte
if (onNewNotification != null) { if (onNewNotification != null) {
@ -72,6 +78,7 @@ class FirebaseNotificationService
} else { } else {
newNotificationCallback(notification); newNotificationCallback(notification);
} }
}
notifyListeners(); notifyListeners();
} on Exception catch (e) { } on Exception catch (e) {
@ -364,7 +371,11 @@ class FirebaseNotificationService
for (var notification in plannedNotifications) { for (var notification in plannedNotifications) {
if (notification.scheduledFor!.isBefore(currentTime) || if (notification.scheduledFor!.isBefore(currentTime) ||
notification.scheduledFor!.isAtSameMomentAs(currentTime)) { notification.scheduledFor!.isAtSameMomentAs(currentTime)) {
await pushNotification(notification, newNotificationCallback); await pushNotification(
notification,
[userId],
newNotificationCallback,
);
await deletePlannedNotification(notification); await deletePlannedNotification(notification);

View file

@ -1,7 +1,7 @@
name: flutter_notification_center_firebase name: flutter_notification_center_firebase
description: "A new Flutter project." description: "A new Flutter project."
publish_to: "none" publish_to: "none"
version: 3.0.0 version: 4.0.0
environment: environment:
sdk: ">=2.18.0 <3.0.0" sdk: ">=2.18.0 <3.0.0"
@ -21,7 +21,7 @@ dependencies:
flutter_notification_center: flutter_notification_center:
git: git:
url: https://github.com/Iconica-Development/flutter_notification_center url: https://github.com/Iconica-Development/flutter_notification_center
ref: 3.0.1 ref: 4.0.0
path: packages/flutter_notification_center path: packages/flutter_notification_center
dev_dependencies: dev_dependencies: