mirror of
https://github.com/Iconica-Development/flutter_notification_center.git
synced 2025-05-18 16:43:44 +02:00
fix: notification center
This commit is contained in:
parent
43a7f44e88
commit
90738db549
7 changed files with 82 additions and 43 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
|
@ -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,
|
||||
]);
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -42,7 +42,8 @@ class FirebaseNotificationService
|
|||
|
||||
@override
|
||||
Future<void> pushNotification(
|
||||
NotificationModel notification, [
|
||||
NotificationModel notification,
|
||||
List<String> 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);
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue