1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-30 00:36:28 +00:00
comunicmobile/lib/ui/screens/group_screen.dart

86 lines
2.2 KiB
Dart
Raw Normal View History

2020-04-15 16:06:20 +00:00
import 'package:comunic/helpers/groups_helper.dart';
2020-04-15 16:23:38 +00:00
import 'package:comunic/ui/screens/authorized_group_page_screen.dart';
2020-04-15 16:06:20 +00:00
import 'package:comunic/ui/screens/group_access_denied_screen.dart';
import 'package:comunic/ui/widgets/safe_state.dart';
import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/material.dart';
/// Group screen
///
/// @author Pierre Hubert
class GroupPageScreen extends StatefulWidget {
final int groupID;
const GroupPageScreen({Key key, @required this.groupID})
: assert(groupID != null),
super(key: key);
@override
_GroupPageScreenState createState() => _GroupPageScreenState();
}
class _GroupPageScreenState extends SafeState<GroupPageScreen> {
int get groupID => widget.groupID;
GetAdvancedInfoResult _getGroupResult;
var error = false;
@override
void initState() {
_refreshPage();
super.initState();
}
@override
Widget build(BuildContext context) {
if (error)
return buildErrorCard(tr("Could not load information about the group!"),
actions: [
MaterialButton(
onPressed: () => _refreshPage(),
child: Text(tr("Try again").toUpperCase()),
)
]);
// If we are still loading the page
if (_getGroupResult == null) return buildCenteredProgressBar();
// Check if access to the group was denied
if (_getGroupResult.status == GetAdvancedInfoStatus.ACCESS_DENIED)
return GroupAccessDeniedScreen(
groupID: groupID,
onMembershipAcquired: () => _refreshPage(),
);
2020-04-15 16:23:38 +00:00
// Now we can show group page
return AuthorizedGroupPageScreen(
advancedGroupInfo: _getGroupResult.info,
needRefresh: () => _refreshPage(),
);
2020-04-15 16:06:20 +00:00
}
/// Refresh the page
Future<void> _refreshPage() async {
try {
setState(() {
error = false;
_getGroupResult = null;
});
// Get information about the group
final result = await GroupsHelper().getAdvancedInfo(groupID);
setState(() {
_getGroupResult = result;
});
} catch (e) {
print(e);
setState(() {
error = true;
});
}
}
}