Skip to content

Commit

Permalink
Merge pull request #27 from Iconica-Development/bugfix/feedback_v2
Browse files Browse the repository at this point in the history
fix: unread notification count, title style, onTap notification
  • Loading branch information
mighttymike authored Sep 5, 2024
2 parents 43a7f44 + 90738db commit ddf2a2b
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 45 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -46,4 +47,6 @@ class NotificationConfig {

/// A builder function to display when there are no notifications.
final Widget Function()? emptyNotificationsBuilder;

final Function(NotificationModel)? onNotificationTap;
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,18 @@ class NotificationCenterState extends State<NotificationCenter> {
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 {
Expand Down Expand Up @@ -170,12 +176,18 @@ class NotificationCenterState extends State<NotificationCenter> {
),
)
: 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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
),
),
],
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ abstract class NotificationService with ChangeNotifier {

/// Pushes a notification to the service.
Future pushNotification(
NotificationModel notification, [
NotificationModel notification,
List<String> recipientIds, [
Function(NotificationModel model)? onNewNotification,
]);

Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_notification_center/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class FirebaseNotificationService

@override
Future<void> pushNotification(
NotificationModel notification, [
NotificationModel notification,
List<String> recipientIds, [
Function(NotificationModel model)? onNewNotification,
]) async {
try {
Expand All @@ -53,24 +54,30 @@ class FirebaseNotificationService
return;
}

CollectionReference notifications =
FirebaseFirestore.instanceFor(app: _firebaseApp)
.collection(activeNotificationsCollection)
.doc(userId)
.collection(activeNotificationsCollection);

var currentDateTime = DateTime.now();
notification.dateTimePushed = currentDateTime;
var notificationMap = notification.toMap();
await notifications.doc(notification.id).set(notificationMap);

listOfActiveNotifications = [...listOfActiveNotifications, notification];

//Show popup with notification conte
if (onNewNotification != null) {
onNewNotification(notification);
} else {
newNotificationCallback(notification);
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);
}
if (recipientIds.contains(userId)) {
listOfActiveNotifications = [
...listOfActiveNotifications,
notification,
];

//Show popup with notification conte
if (onNewNotification != null) {
onNewNotification(notification);
} else {
newNotificationCallback(notification);
}
}

notifyListeners();
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions packages/flutter_notification_center_firebase/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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:
Expand Down

0 comments on commit ddf2a2b

Please sign in to comment.