mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-03 19:54:12 +00:00 
			
		
		
		
	Can delete notifications from notifications screen
This commit is contained in:
		@@ -17,6 +17,8 @@ import 'package:flutter/material.dart';
 | 
			
		||||
 | 
			
		||||
enum _Status { LOADING, ERROR, NONE }
 | 
			
		||||
 | 
			
		||||
enum _PopupMenuActions { DELETE }
 | 
			
		||||
 | 
			
		||||
class NotificationsScreen extends StatefulWidget {
 | 
			
		||||
  @override
 | 
			
		||||
  _NotificationsScreenState createState() => _NotificationsScreenState();
 | 
			
		||||
@@ -93,6 +95,7 @@ class _NotificationsScreenState extends State<NotificationsScreen> {
 | 
			
		||||
                notification: f,
 | 
			
		||||
                usersList: _users,
 | 
			
		||||
                groupsList: _groups,
 | 
			
		||||
                onDelete: _deleteNotification,
 | 
			
		||||
              ))
 | 
			
		||||
          .toList(),
 | 
			
		||||
    );
 | 
			
		||||
@@ -118,19 +121,33 @@ class _NotificationsScreenState extends State<NotificationsScreen> {
 | 
			
		||||
        ),
 | 
			
		||||
      );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Delete a notification
 | 
			
		||||
  void _deleteNotification(n.Notification notif) async {
 | 
			
		||||
    setState(() {
 | 
			
		||||
      _list.remove(notif);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    NotificationsHelper().markSeen(notif);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class _NotificationTile extends StatelessWidget {
 | 
			
		||||
  final n.Notification notification;
 | 
			
		||||
  final UsersList usersList;
 | 
			
		||||
  final GroupsList groupsList;
 | 
			
		||||
  final void Function(n.Notification) onDelete;
 | 
			
		||||
 | 
			
		||||
  const _NotificationTile({
 | 
			
		||||
    Key key,
 | 
			
		||||
    @required this.notification,
 | 
			
		||||
    @required this.usersList,
 | 
			
		||||
    @required this.groupsList,
 | 
			
		||||
    @required this.onDelete,
 | 
			
		||||
  })  : assert(notification != null),
 | 
			
		||||
        assert(usersList != null),
 | 
			
		||||
        assert(groupsList != null),
 | 
			
		||||
        assert(onDelete != null),
 | 
			
		||||
        super(key: key);
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
@@ -227,6 +244,23 @@ class _NotificationTile extends StatelessWidget {
 | 
			
		||||
      ),
 | 
			
		||||
      title: Text(message),
 | 
			
		||||
      subtitle: Text(diffTimeFromNowToStr(notification.timeCreate)),
 | 
			
		||||
      trailing: PopupMenuButton<_PopupMenuActions>(
 | 
			
		||||
        onSelected: _popupMenuAction,
 | 
			
		||||
        itemBuilder: (c) => [
 | 
			
		||||
          PopupMenuItem(
 | 
			
		||||
            child: Text(tr("Delete")),
 | 
			
		||||
            value: _PopupMenuActions.DELETE,
 | 
			
		||||
          ),
 | 
			
		||||
        ],
 | 
			
		||||
      ),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void _popupMenuAction(_PopupMenuActions value) {
 | 
			
		||||
    switch (value) {
 | 
			
		||||
      case _PopupMenuActions.DELETE:
 | 
			
		||||
        onDelete(notification);
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user