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:
Gorter-dev 2024-04-17 14:23:16 +02:00 committed by GitHub
commit 2d0f69e908
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 107 additions and 20 deletions

View file

@ -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

View file

@ -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,
),
),
),
],

View file

@ -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;

View file

@ -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,

View file

@ -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);

View file

@ -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 {

View file

@ -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'