showKickAndBanUserDialog function
Future<void>
showKickAndBanUserDialog( - dynamic context,
- dynamic member
)
Implementation
Future<void> showKickAndBanUserDialog(
BuildContext context,
Member member,
) async {
final userId = member.userId().toString();
final roomId = member.roomIdStr();
await showDialog(
context: context,
builder: (BuildContext context) {
final reason = TextEditingController();
return AlertDialog(
title: Text(L10n.of(context).kickAndBanUserTitle(userId)),
content: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(L10n.of(context).kickAndBanUserDescription(userId, roomId)),
Text(L10n.of(context).theyWontBeAbleToJoinAgain),
TextFormField(
controller: reason,
decoration: InputDecoration(
hintText: L10n.of(context).reasonHint,
labelText: L10n.of(context).reasonLabel,
),
),
Text(L10n.of(context).continueQuestion),
],
),
),
actionsAlignment: MainAxisAlignment.spaceEvenly,
actions: <Widget>[
OutlinedButton(
onPressed: () => Navigator.pop(context),
child: Text(L10n.of(context).no),
),
ActerPrimaryActionButton(
onPressed: () async {
EasyLoading.show(status: L10n.of(context).kickAndBanProgress);
try {
final maybeReason = reason.text.isNotEmpty ? reason.text : null;
await member.kick(maybeReason);
await member.ban(maybeReason);
if (!context.mounted) {
EasyLoading.dismiss();
return;
}
EasyLoading.showToast(L10n.of(context).kickAndBanSuccess);
Navigator.pop(context);
} catch (e, s) {
_log.severe('Failed to kick and ban user', e, s);
if (!context.mounted) {
EasyLoading.dismiss();
return;
}
EasyLoading.showError(
L10n.of(context).kickAndBanFailed(e),
duration: const Duration(seconds: 3),
);
}
},
child: Text(L10n.of(context).yes),
),
],
);
},
);
}