1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 21:09:21 +00:00
comunicmobile/lib/ui/screens/group_screen.dart

91 lines
2.3 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;
2021-04-06 16:22:45 +00:00
final int conversationID;
2020-04-15 16:06:20 +00:00
2021-04-06 16:22:45 +00:00
const GroupPageScreen({
Key key,
@required this.groupID,
this.conversationID,
}) : assert(groupID != null),
2020-04-15 16:06:20 +00:00
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,
2021-04-06 16:22:45 +00:00
conversationID: widget.conversationID,
2020-04-15 16:23:38 +00:00
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;
});
}
}
}