2019-11-01 14:37:27 +00:00
|
|
|
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';
|
2019-11-01 13:55:28 +00:00
|
|
|
import 'package:comunic/lists/notifications_list.dart';
|
2019-11-01 14:37:27 +00:00
|
|
|
import 'package:comunic/lists/users_list.dart';
|
2019-11-01 13:55:28 +00:00
|
|
|
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;
|
2019-11-01 14:37:27 +00:00
|
|
|
UsersList _users;
|
|
|
|
GroupsList _groups;
|
2019-11-01 13:55:28 +00:00
|
|
|
_Status _status = _Status.LOADING;
|
|
|
|
|
|
|
|
void setStatus(_Status s) => setState(() => _status = s);
|
|
|
|
|
|
|
|
Future<void> _loadList() async {
|
|
|
|
setStatus(_Status.LOADING);
|
|
|
|
|
2019-11-01 14:37:27 +00:00
|
|
|
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();
|
2019-11-01 13:55:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@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(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|