mirror of
https://github.com/Iconica-Development/flutter_notification_center.git
synced 2025-05-19 09:03:45 +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
|
## [2.0.0] - 6 June 2024
|
||||||
|
|
||||||
* Rework design for notification center
|
* Rework design for notification center
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
||||||
context,
|
if (widget.config.onNotificationTap != null) {
|
||||||
notification,
|
widget.config.onNotificationTap!.call(notification);
|
||||||
widget.config.service,
|
} else {
|
||||||
widget.config.translations,
|
await _navigateToNotificationDetail(
|
||||||
),
|
context,
|
||||||
|
notification,
|
||||||
|
widget.config.service,
|
||||||
|
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 {
|
||||||
context,
|
if (widget.config.onNotificationTap != null) {
|
||||||
notification,
|
widget.config.onNotificationTap!.call(notification);
|
||||||
widget.config.service,
|
} else {
|
||||||
widget.config.translations,
|
await _navigateToNotificationDetail(
|
||||||
),
|
context,
|
||||||
|
notification,
|
||||||
|
widget.config.service,
|
||||||
|
widget.config.translations,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
child: Dismissible(
|
child: Dismissible(
|
||||||
key: Key(notification.id),
|
key: Key(notification.id),
|
||||||
onDismissed: (direction) async {
|
onDismissed: (direction) async {
|
||||||
|
@ -274,16 +286,20 @@ 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(
|
||||||
Icons.circle_rounded,
|
padding: EdgeInsets.only(top: 8),
|
||||||
color: Colors.black,
|
child: Icon(
|
||||||
size: 8,
|
Icons.circle_rounded,
|
||||||
|
color: Colors.black,
|
||||||
|
size: 8,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
width: 8,
|
width: 8,
|
||||||
|
@ -305,11 +321,13 @@ Widget _notificationItem(
|
||||||
width: 8,
|
width: 8,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
Text(
|
Flexible(
|
||||||
notification.title,
|
child: Text(
|
||||||
style: notification.isRead && !notification.isPinned
|
notification.title,
|
||||||
? theme.textTheme.bodyMedium
|
style: notification.isRead && !notification.isPinned
|
||||||
: theme.textTheme.titleMedium,
|
? theme.textTheme.bodyMedium
|
||||||
|
: theme.textTheme.titleMedium,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
@ -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,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
@ -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"
|
||||||
|
|
|
@ -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,24 +54,30 @@ class FirebaseNotificationService
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CollectionReference notifications =
|
for (var recipientId in recipientIds) {
|
||||||
FirebaseFirestore.instanceFor(app: _firebaseApp)
|
CollectionReference notifications =
|
||||||
.collection(activeNotificationsCollection)
|
FirebaseFirestore.instanceFor(app: _firebaseApp)
|
||||||
.doc(userId)
|
.collection(activeNotificationsCollection)
|
||||||
.collection(activeNotificationsCollection);
|
.doc(recipientId)
|
||||||
|
.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);
|
||||||
|
}
|
||||||
|
if (recipientIds.contains(userId)) {
|
||||||
|
listOfActiveNotifications = [
|
||||||
|
...listOfActiveNotifications,
|
||||||
|
notification,
|
||||||
|
];
|
||||||
|
|
||||||
listOfActiveNotifications = [...listOfActiveNotifications, notification];
|
//Show popup with notification conte
|
||||||
|
if (onNewNotification != null) {
|
||||||
//Show popup with notification conte
|
onNewNotification(notification);
|
||||||
if (onNewNotification != null) {
|
} else {
|
||||||
onNewNotification(notification);
|
newNotificationCallback(notification);
|
||||||
} else {
|
}
|
||||||
newNotificationCallback(notification);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -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:
|
||||||
|
|
Loading…
Reference in a new issue