From 0700014b3a7888fc6975c2cfcf3aaf830d6c5ae8 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 18 Apr 2020 14:17:14 +0200 Subject: [PATCH] Automatically refresh the list of notifications when required --- lib/ui/screens/notifications_screen.dart | 32 ++++++++++++++++-------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/ui/screens/notifications_screen.dart b/lib/ui/screens/notifications_screen.dart index f03a9bb..7b0d47f 100644 --- a/lib/ui/screens/notifications_screen.dart +++ b/lib/ui/screens/notifications_screen.dart @@ -1,3 +1,4 @@ +import 'package:comunic/helpers/events_helper.dart'; import 'package:comunic/helpers/groups_helper.dart'; import 'package:comunic/helpers/notifications_helper.dart'; import 'package:comunic/helpers/users_helper.dart'; @@ -7,6 +8,7 @@ import 'package:comunic/lists/users_list.dart'; import 'package:comunic/models/notification.dart' as n; import 'package:comunic/ui/routes/main_route.dart'; import 'package:comunic/ui/widgets/account_image_widget.dart'; +import 'package:comunic/ui/widgets/safe_state.dart'; import 'package:comunic/utils/date_utils.dart'; import 'package:comunic/utils/intl_utils.dart'; import 'package:comunic/utils/navigation_utils.dart'; @@ -26,7 +28,7 @@ class NotificationsScreen extends StatefulWidget { _NotificationsScreenState createState() => _NotificationsScreenState(); } -class _NotificationsScreenState extends State { +class _NotificationsScreenState extends SafeState { NotificationsList _list; UsersList _users; GroupsList _groups; @@ -62,6 +64,14 @@ class _NotificationsScreenState extends State { } } + @override + void initState() { + super.initState(); + + this.listenChangeState( + (d) => _refreshKey.currentState.show()); + } + @override void didChangeDependencies() { super.didChangeDependencies(); @@ -111,11 +121,11 @@ class _NotificationsScreenState extends State { return ListView( children: _list .map((f) => _NotificationTile( - notification: f, - usersList: _users, - groupsList: _groups, - onDelete: _deleteNotification, - )) + notification: f, + usersList: _users, + groupsList: _groups, + onDelete: _deleteNotification, + )) .toList(), ); } @@ -193,12 +203,12 @@ class _NotificationTile extends StatelessWidget { String message = "${srcUser.fullName} "; switch (notification.type) { - // Comment + // Comment case n.NotificationType.COMMENT_CREATED: message += tr("posted a comment"); break; - // Friendship requests + // Friendship requests case n.NotificationType.SENT_FRIEND_REQUEST: message += tr("sent you a friendship request."); break; @@ -211,7 +221,7 @@ class _NotificationTile extends StatelessWidget { message += tr("rejected your friendship request."); break; - // Groups membership + // Groups membership case n.NotificationType.SENT_GROUP_MEMBERSHIP_INVITATION: message += tr("invited you to join the group"); break; @@ -236,14 +246,14 @@ class _NotificationTile extends StatelessWidget { message += tr("rejected your request to join the group"); break; - // Generic element creation + // Generic element creation case n.NotificationType.ELEM_CREATED: if (notification.onElemType == n.NotificationElementType.POST) message += tr("created a new post"); break; case n.NotificationType.ELEM_UPDATED: - // Operation not implemented + // Operation not implemented break; }