mirror of
https://github.com/Iconica-Development/flutter_notification_center.git
synced 2025-05-19 00:53:44 +02:00
Merge pull request #5 from Iconica-Development/feat/swipe-to-pin-notification
feat: add functionality to pin notifications by swiping
This commit is contained in:
commit
2d0f69e908
7 changed files with 107 additions and 20 deletions
|
@ -1,6 +1,10 @@
|
|||
## [1.2.0] - 17 April 2024
|
||||
|
||||
* Add functionality to pin notifications by swiping
|
||||
|
||||
## [1.1.0] - 15 April 2024
|
||||
|
||||
* Initial Release
|
||||
* Add option for snackbar and dialog popups
|
||||
|
||||
## [1.0.0] - 14 April 2024
|
||||
|
||||
|
|
|
@ -56,23 +56,44 @@ class CustomNotificationWidget extends StatelessWidget {
|
|||
: Dismissible(
|
||||
key: Key(notification.id),
|
||||
onDismissed: (direction) async {
|
||||
await dismissNotification(notificationService, notification);
|
||||
if (direction == DismissDirection.endToStart) {
|
||||
await dismissNotification(notificationService, notification);
|
||||
} else if (direction == DismissDirection.startToEnd) {
|
||||
await pinNotification(
|
||||
notificationService, notification, context);
|
||||
}
|
||||
},
|
||||
background: Container(
|
||||
color: Colors.red,
|
||||
color: const Color.fromRGBO(59, 213, 111, 1),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.only(left: 16.0),
|
||||
child: Icon(
|
||||
Icons.push_pin,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
secondaryBackground: Container(
|
||||
color: const Color.fromRGBO(255, 131, 131, 1),
|
||||
alignment: Alignment.centerRight,
|
||||
child: const Icon(
|
||||
Icons.delete,
|
||||
color: Colors.white,
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.only(right: 16.0),
|
||||
child: Icon(
|
||||
Icons.delete,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: GestureDetector(
|
||||
onTap: () async =>
|
||||
_navigateToNotificationDetail(context, notification),
|
||||
onTap: () async => _navigateToNotificationDetail(
|
||||
context,
|
||||
notification,
|
||||
),
|
||||
child: ListTile(
|
||||
leading: Icon(
|
||||
notification.icon,
|
||||
color: style.leadingIconColor,
|
||||
color: Colors.grey,
|
||||
),
|
||||
title: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
@ -80,7 +101,11 @@ class CustomNotificationWidget extends StatelessWidget {
|
|||
Expanded(
|
||||
child: Text(
|
||||
notification.title,
|
||||
style: style.titleTextStyle,
|
||||
style: const TextStyle(
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
|
|
@ -85,7 +85,7 @@ class NotificationModel {
|
|||
final OcurringInterval? occuringInterval;
|
||||
|
||||
/// Indicates if the notification is pinned.
|
||||
final bool isPinned;
|
||||
bool isPinned;
|
||||
|
||||
/// Indicates if the notification has been read.
|
||||
bool isRead;
|
||||
|
|
|
@ -136,17 +136,42 @@ class NotificationCenterState extends State<NotificationCenter> {
|
|||
: Dismissible(
|
||||
key: Key(notification.id),
|
||||
onDismissed: (direction) async {
|
||||
await dismissNotification(
|
||||
widget.config.service,
|
||||
notification,
|
||||
context);
|
||||
if (direction ==
|
||||
DismissDirection.endToStart) {
|
||||
await dismissNotification(
|
||||
widget.config.service,
|
||||
notification,
|
||||
context);
|
||||
} else if (direction ==
|
||||
DismissDirection.startToEnd) {
|
||||
await pinNotification(
|
||||
widget.config.service,
|
||||
notification,
|
||||
context);
|
||||
}
|
||||
},
|
||||
background: Container(
|
||||
color: Colors.red,
|
||||
color:
|
||||
const Color.fromRGBO(59, 213, 111, 1),
|
||||
alignment: Alignment.centerLeft,
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.only(left: 16.0),
|
||||
child: Icon(
|
||||
Icons.push_pin,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
secondaryBackground: Container(
|
||||
color:
|
||||
const Color.fromRGBO(255, 131, 131, 1),
|
||||
alignment: Alignment.centerRight,
|
||||
child: const Icon(
|
||||
Icons.delete,
|
||||
color: Colors.white,
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.only(right: 16.0),
|
||||
child: Icon(
|
||||
Icons.delete,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: GestureDetector(
|
||||
|
@ -238,6 +263,21 @@ Future<void> dismissNotification(
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> pinNotification(
|
||||
NotificationService notificationService,
|
||||
NotificationModel notification,
|
||||
BuildContext context,
|
||||
) async {
|
||||
await notificationService.pinActiveNotification(notification);
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text("Notification pinned"),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> markNotificationAsRead(
|
||||
NotificationService notificationService,
|
||||
NotificationModel notification,
|
||||
|
|
|
@ -44,6 +44,9 @@ abstract class NotificationService with ChangeNotifier {
|
|||
/// Dismisses an active notification.
|
||||
Future dismissActiveNotification(NotificationModel notification);
|
||||
|
||||
/// Pin an active notification.
|
||||
Future pinActiveNotification(NotificationModel notification);
|
||||
|
||||
/// Marks a notification as read.
|
||||
Future markNotificationAsRead(NotificationModel notification);
|
||||
|
||||
|
|
|
@ -164,6 +164,21 @@ class FirebaseNotificationService
|
|||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> pinActiveNotification(
|
||||
NotificationModel notificationModel) async {
|
||||
try {
|
||||
DocumentReference documentReference = FirebaseFirestore.instance
|
||||
.collection(FirebaseCollectionNames.activeNotifications)
|
||||
.doc(notificationModel.id);
|
||||
await documentReference.update({'isPinned': true});
|
||||
notificationModel.isPinned = true;
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
debugPrint('Error updating document: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> markNotificationAsRead(
|
||||
NotificationModel notificationModel) async {
|
||||
|
|
|
@ -4,7 +4,7 @@ description: "A new Flutter project."
|
|||
# pub.dev using `flutter pub publish`. This is preferred for private packages.
|
||||
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||
|
||||
version: 1.1.0
|
||||
version: 1.2.0
|
||||
|
||||
environment:
|
||||
sdk: '>=3.3.2 <4.0.0'
|
||||
|
|
Loading…
Reference in a new issue