showSpaceInvitationDialog function
Future<bool>
showSpaceInvitationDialog({
- required BuildContext context,
- required Space space,
- List<
Role> allowedRoles = Role.values, - ApptiveLinkType type = ApptiveLinkType.invite,
- InvitationLocalization? localization,
Shows a Dialog to invite/add someone to a Space
space
is the Space
that should be shared. Space.links
needs to contain the Link for type
Also type
needs to be either ApptiveLinkType.invite
or ApptiveLinkType.addSpace
Note: Even when using ApptiveLinkType.addSpace
the Ui will display Strings pointing to the user being invited to a space
This can be prevented by using a custom localization
It is also possible to define which roles
can be added. This can't be empty. Also if it only contains one Role
the selection box is not shown
This will return a Future
Implementation
Future<bool> showSpaceInvitationDialog({
required BuildContext context,
required Space space,
List<Role> allowedRoles = Role.values,
ApptiveLinkType type = ApptiveLinkType.invite,
InvitationLocalization? localization,
}) async {
assert(type == ApptiveLinkType.invite || type == ApptiveLinkType.addShare);
assert(space.links.containsKey(type));
assert(allowedRoles.isNotEmpty);
final l10n = localization ??
(Localizations.localeOf(context).languageCode == 'de'
? const InvitationLocalizationDE()
: const InvitationLocalizationEn());
TextEditingController emailController = TextEditingController();
ValueNotifier<Role> roleNotifier = ValueNotifier(allowedRoles.first);
ValueNotifier<bool> loading = ValueNotifier(false);
ValueNotifier<dynamic> errorNotifier = ValueNotifier(null);
bool dialogResult = false;
return showDialog(
context: context,
builder: (dialogContext) {
return ValueListenableBuilder<bool>(
valueListenable: loading,
builder: (_, loading, child) => IgnorePointer(
ignoring: loading,
child: child,
),
child: Form(
child: AlertDialog(
title: Text.rich(
TextSpan(
children: getHighlightSpans(
getText: l10n.title,
highlight: space.name,
highlightStyle: TextStyle(
color: Theme.of(context).colorScheme.primary,
),
),
),
),
content: _InvitationDialogContent(
emailController: emailController,
role: roleNotifier,
error: errorNotifier,
allowedRoles: allowedRoles,
localization: l10n,
),
actions: [
TextButton(
onPressed: Navigator.of(dialogContext).pop,
child: Text(l10n.actionCancel),
),
_InvitationSendButton(
client: ApptiveGrid.getClient(context),
loading: loading,
role: roleNotifier,
error: errorNotifier,
onInviteSend: (email) {
dialogResult = true;
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text.rich(
TextSpan(
children: getHighlightSpans(
getText: l10n.inviteSend,
highlight: email,
highlightStyle:
const TextStyle(fontWeight: FontWeight.bold),
),
),
),
),
);
}
},
localization: l10n,
email: emailController,
link: space.links[type]!,
),
],
),
),
);
},
).then((_) => dialogResult);
}