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

90 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;
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,
2021-04-06 16:22:45 +00:00
this.conversationID,
2022-03-11 16:02:06 +00:00
}) : super(key: key);
2020-04-15 16:06:20 +00:00
@override
_GroupPageScreenState createState() => _GroupPageScreenState();
}
class _GroupPageScreenState extends SafeState<GroupPageScreen> {
int get groupID => widget.groupID;
GetAdvancedInfoResult? _getGroupResult;
2020-04-15 16:06:20 +00:00
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()),
2020-04-15 16:06:20 +00:00
)
]);
// 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)
2020-04-15 16:06:20 +00:00
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;
});
}
}
}