2020-04-15 16:06:20 +00:00
|
|
|
import 'package:comunic/helpers/groups_helper.dart';
|
|
|
|
import 'package:comunic/models/group.dart';
|
|
|
|
import 'package:comunic/ui/widgets/group_icon_widget.dart';
|
|
|
|
import 'package:comunic/ui/widgets/group_membership_widget.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 access denied screen
|
|
|
|
///
|
|
|
|
/// @author Pierre Hubert
|
|
|
|
|
|
|
|
class GroupAccessDeniedScreen extends StatefulWidget {
|
|
|
|
final int groupID;
|
|
|
|
final Function() onMembershipAcquired;
|
|
|
|
|
|
|
|
const GroupAccessDeniedScreen({
|
2022-03-10 18:39:57 +00:00
|
|
|
Key? key,
|
|
|
|
required this.groupID,
|
|
|
|
required this.onMembershipAcquired,
|
2022-03-11 16:02:06 +00:00
|
|
|
}) : super(key: key);
|
2020-04-15 16:06:20 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
_GroupAccessDeniedScreenState createState() =>
|
|
|
|
_GroupAccessDeniedScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _GroupAccessDeniedScreenState extends SafeState<GroupAccessDeniedScreen> {
|
2022-03-10 18:39:57 +00:00
|
|
|
Group? _group;
|
2020-04-15 16:06:20 +00:00
|
|
|
|
|
|
|
bool error = false;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
_refresh();
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
if (error)
|
|
|
|
return buildErrorCard(tr("Could not get basic group information!"),
|
|
|
|
actions: [
|
|
|
|
MaterialButton(
|
2022-03-10 18:39:57 +00:00
|
|
|
child: Text(tr("Try again")!.toUpperCase()),
|
2020-04-15 16:06:20 +00:00
|
|
|
onPressed: () => this._refresh(),
|
|
|
|
)
|
|
|
|
]);
|
|
|
|
|
|
|
|
if (_group == null) return buildCenteredProgressBar();
|
|
|
|
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: Center(
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
Spacer(
|
|
|
|
flex: 5,
|
|
|
|
),
|
2022-03-10 18:39:57 +00:00
|
|
|
GroupIcon(group: _group!),
|
2020-04-15 16:06:20 +00:00
|
|
|
Spacer(),
|
|
|
|
Text(
|
2022-03-10 18:39:57 +00:00
|
|
|
_group!.displayName,
|
2020-04-15 16:06:20 +00:00
|
|
|
style: TextStyle(fontSize: 20),
|
|
|
|
),
|
|
|
|
Spacer(),
|
2021-04-23 17:41:14 +00:00
|
|
|
Text(
|
2022-03-10 18:39:57 +00:00
|
|
|
tr("A registration is required to access this group page.")!,
|
2021-04-23 17:41:14 +00:00
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
2020-04-15 16:06:20 +00:00
|
|
|
Spacer(),
|
|
|
|
GroupMembershipWidget(
|
2022-03-10 18:39:57 +00:00
|
|
|
group: _group!,
|
2020-04-15 16:06:20 +00:00
|
|
|
onUpdated: () => this._refresh(),
|
|
|
|
onError: () => this._refresh(),
|
|
|
|
),
|
|
|
|
Spacer(
|
|
|
|
flex: 5,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get basic information about the groups
|
|
|
|
Future<void> _refresh() async {
|
|
|
|
try {
|
|
|
|
setState(() {
|
|
|
|
error = false;
|
|
|
|
_group = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Get information about a single group
|
|
|
|
final group = await GroupsHelper().getSingle(widget.groupID, force: true);
|
|
|
|
|
2020-04-15 16:39:07 +00:00
|
|
|
if (group.isAtLeastMember) widget.onMembershipAcquired();
|
2020-04-15 16:06:20 +00:00
|
|
|
|
|
|
|
setState(() => _group = group);
|
|
|
|
} catch (e) {
|
|
|
|
print(e);
|
|
|
|
setState(() => error = true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|