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;
|
2022-03-10 18:39:57 +00:00
|
|
|
final int? conversationID;
|
2020-04-15 16:06:20 +00:00
|
|
|
|
2021-04-06 16:22:45 +00:00
|
|
|
const GroupPageScreen({
|
2022-03-10 18:39:57 +00:00
|
|
|
Key? key,
|
|
|
|
required this.groupID,
|
2021-04-06 16:22:45 +00:00
|
|
|
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;
|
|
|
|
|
2022-03-10 18:39:57 +00:00
|
|
|
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(),
|
2022-03-10 18:39:57 +00:00
|
|
|
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
|
2022-03-10 18:39:57 +00:00
|
|
|
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(
|
2022-03-10 18:39:57 +00:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|