diff --git a/lib/helpers/notifications_helper.dart b/lib/helpers/notifications_helper.dart index 2702bf9..360946b 100644 --- a/lib/helpers/notifications_helper.dart +++ b/lib/helpers/notifications_helper.dart @@ -102,4 +102,10 @@ class NotificationsHelper { }, ).exec()) .isOK; + + /// Delete all unread notifications + Future deleteAllNotifications() async => + (await APIRequest(uri: "notifications/delete_all", needLogin: true) + .exec()) + .isOK; } diff --git a/lib/ui/screens/notifications_screen.dart b/lib/ui/screens/notifications_screen.dart index 0b1baa5..de95ec4 100644 --- a/lib/ui/screens/notifications_screen.dart +++ b/lib/ui/screens/notifications_screen.dart @@ -32,6 +32,8 @@ class _NotificationsScreenState extends State { GroupsList _groups; _Status _status = _Status.LOADING; + final _refreshKey = GlobalKey(); + void setStatus(_Status s) => setState(() => _status = s); Future _loadList() async { @@ -77,7 +79,22 @@ class _NotificationsScreenState extends State { return Column( children: [ Expanded( - child: RefreshIndicator(child: _buildBody(), onRefresh: _loadList), + child: Stack(children: [ + RefreshIndicator( + key: _refreshKey, + child: _buildBody(), + onRefresh: _loadList, + ), + // Add conversation button + Positioned( + right: 20.0, + bottom: 20.0, + child: FloatingActionButton( + onPressed: () => _deleteAllNotifications(), + child: Icon(Icons.delete), + ), + ), + ]), ) ], ); @@ -134,6 +151,21 @@ class _NotificationsScreenState extends State { NotificationsHelper().markSeen(notif); } + + /// Delete all the notifications + void _deleteAllNotifications() async { + if (!await showConfirmDialog( + context: context, + message: tr("Do you really want to delete all your notifications?"))) + return; + + if (!await NotificationsHelper().deleteAllNotifications()) { + showSimpleSnack(context, tr("Could not delete all your notifications!")); + return; + } + + _refreshKey.currentState.show(); + } } class _NotificationTile extends StatelessWidget {