1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-10-23 15:03:22 +00:00
comunicmobile/lib/ui/screens/notifications_screen.dart

79 lines
2.1 KiB
Dart

import 'package:comunic/helpers/groups_helper.dart';
import 'package:comunic/helpers/notifications_helper.dart';
import 'package:comunic/helpers/users_helper.dart';
import 'package:comunic/lists/groups_list.dart';
import 'package:comunic/lists/notifications_list.dart';
import 'package:comunic/lists/users_list.dart';
import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/material.dart';
/// Notifications screen
///
/// @author Pierre HUBERT
enum _Status { LOADING, ERROR, NONE }
class NotificationsScreen extends StatefulWidget {
@override
_NotificationsScreenState createState() => _NotificationsScreenState();
}
class _NotificationsScreenState extends State<NotificationsScreen> {
NotificationsList _list;
UsersList _users;
GroupsList _groups;
_Status _status = _Status.LOADING;
void setStatus(_Status s) => setState(() => _status = s);
Future<void> _loadList() async {
setStatus(_Status.LOADING);
try {
final list = await NotificationsHelper().getUnread();
final users = await UsersHelper().getListWithThrow(list.usersIds);
final groups = await GroupsHelper().getListOrThrow(list.groupsIds);
setState(() {
_list = list;
_users = users;
_groups = groups;
});
} on Exception catch (e) {
print("Exception while getting the list of notifications!");
print(e);
} on Error catch (e) {
print("Error while getting the list of notifications!");
print(e.stackTrace);
}
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
_loadList();
}
@override
Widget build(BuildContext context) {
// In case of error
if (_status == _Status.ERROR)
return buildErrorCard(tr("Could not get the list of notifications!"),
actions: [
MaterialButton(
onPressed: () => _loadList(),
child: Text(tr("Try again".toUpperCase())),
)
]);
// Loading status
if (_list == null || _status == _Status.LOADING)
return Center(
child: CircularProgressIndicator(),
);
}
}