Skip to content

feat(firebase_ui_auth): Override the default deletion modal #493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/firebase_ui_auth/lib/src/screens/profile_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,9 @@ class ProfileScreen extends MultiProviderScreen {
/// {@macro ui.auth.widgets.delete_account_button.show_delete_confirmation_dialog}
final bool showDeleteConfirmationDialog;

/// {@macro ui.auth.widgets.delete_account_button.delete_confirmation}
final Future<bool> Function(BuildContext context)? deleteConfirmation;

const ProfileScreen({
super.key,
super.auth,
Expand All @@ -770,6 +773,7 @@ class ProfileScreen extends MultiProviderScreen {
this.showMFATile = false,
this.showUnlinkConfirmationDialog = false,
this.showDeleteConfirmationDialog = false,
this.deleteConfirmation,
});

Future<bool> _reauthenticate(BuildContext context) {
Expand Down Expand Up @@ -931,6 +935,7 @@ class ProfileScreen extends MultiProviderScreen {
DeleteAccountButton(
auth: auth,
showDeleteConfirmationDialog: showDeleteConfirmationDialog,
deleteConfirmation: deleteConfirmation,
onSignInRequired: () {
return _reauthenticate(context);
},
Expand Down
2 changes: 1 addition & 1 deletion packages/firebase_ui_auth/lib/src/styling/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ StylesMap _buildStylesMap(Set<FirebaseUIStyle> styles) {
/// Shouldn't be used if you're using pre-built screens, but could be used
/// if you're building your own and using only widgets from the FirebaseUI.
class FirebaseUITheme extends InheritedModel {
/// A set of styles that need to be provded down the widget tree.
/// A set of styles that need to be provided down the widget tree.
final Set<FirebaseUIStyle> styles;

const FirebaseUITheme({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class DeleteAccountButton extends StatefulWidget {
/// {@endtemplate}
final bool showDeleteConfirmationDialog;

/// {@template ui.auth.widgets.delete_account_button.delete_confirmation}
/// A callback to replace the default account deletion modal.
/// {@endtemplate}
final Future<bool> Function(BuildContext context)? deleteConfirmation;

/// {@macro ui.auth.widgets.delete_account_button}
const DeleteAccountButton({
super.key,
Expand All @@ -71,6 +76,7 @@ class DeleteAccountButton extends StatefulWidget {
this.onDeleteFailed,
this.variant = ButtonVariant.filled,
this.showDeleteConfirmationDialog = false,
this.deleteConfirmation,
});

@override
Expand All @@ -91,19 +97,23 @@ class _DeleteAccountButtonState extends State<DeleteAccountButton> {
if (!confirmed) {
final l = FirebaseUILocalizations.labelsOf(context);

confirmed = await showCupertinoDialog<bool?>(
context: context,
builder: (context) {
return UniversalAlert(
onConfirm: pop(context, true),
onCancel: pop(context, false),
title: l.confirmDeleteAccountAlertTitle,
confirmButtonText: l.confirmDeleteAccountButtonLabel,
cancelButtonText: l.cancelButtonLabel,
message: l.confirmDeleteAccountAlertMessage,
);
},
);
if (widget.deleteConfirmation != null) {
confirmed = await widget.deleteConfirmation!(context);
} else {
confirmed = await showCupertinoDialog<bool?>(
context: context,
builder: (context) {
return UniversalAlert(
onConfirm: pop(context, true),
onCancel: pop(context, false),
title: l.confirmDeleteAccountAlertTitle,
confirmButtonText: l.confirmDeleteAccountButtonLabel,
cancelButtonText: l.cancelButtonLabel,
message: l.confirmDeleteAccountAlertMessage,
);
},
);
}
}

if (!(confirmed ?? false)) return;
Expand Down
Loading