Skip to content

Commit 9721090

Browse files
feat(firebase_ui_auth): Override the default deletion modal. (#493)
Co-authored-by: russellwheatley <[email protected]>
1 parent 2747c1a commit 9721090

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

packages/firebase_ui_auth/lib/src/screens/profile_screen.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,9 @@ class ProfileScreen extends MultiProviderScreen {
751751
/// {@macro ui.auth.widgets.delete_account_button.show_delete_confirmation_dialog}
752752
final bool showDeleteConfirmationDialog;
753753

754+
/// {@macro ui.auth.widgets.delete_account_button.delete_confirmation}
755+
final Future<bool> Function(BuildContext context)? deleteConfirmation;
756+
754757
const ProfileScreen({
755758
super.key,
756759
super.auth,
@@ -767,6 +770,7 @@ class ProfileScreen extends MultiProviderScreen {
767770
this.showMFATile = false,
768771
this.showUnlinkConfirmationDialog = false,
769772
this.showDeleteConfirmationDialog = false,
773+
this.deleteConfirmation,
770774
});
771775

772776
Future<bool> _reauthenticate(BuildContext context) {
@@ -928,6 +932,7 @@ class ProfileScreen extends MultiProviderScreen {
928932
DeleteAccountButton(
929933
auth: auth,
930934
showDeleteConfirmationDialog: showDeleteConfirmationDialog,
935+
deleteConfirmation: deleteConfirmation,
931936
onSignInRequired: () {
932937
return _reauthenticate(context);
933938
},

packages/firebase_ui_auth/lib/src/styling/theme.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ StylesMap _buildStylesMap(Set<FirebaseUIStyle> styles) {
2222
/// Shouldn't be used if you're using pre-built screens, but could be used
2323
/// if you're building your own and using only widgets from the FirebaseUI.
2424
class FirebaseUITheme extends InheritedModel {
25-
/// A set of styles that need to be provded down the widget tree.
25+
/// A set of styles that need to be provided down the widget tree.
2626
final Set<FirebaseUIStyle> styles;
2727

2828
const FirebaseUITheme({

packages/firebase_ui_auth/lib/src/widgets/delete_account_button.dart

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ class DeleteAccountButton extends StatefulWidget {
6363
/// {@endtemplate}
6464
final bool showDeleteConfirmationDialog;
6565

66+
/// {@template ui.auth.widgets.delete_account_button.delete_confirmation}
67+
/// A callback to replace the default account deletion modal.
68+
/// {@endtemplate}
69+
final Future<bool> Function(BuildContext context)? deleteConfirmation;
70+
6671
/// {@macro ui.auth.widgets.delete_account_button}
6772
const DeleteAccountButton({
6873
super.key,
@@ -71,6 +76,7 @@ class DeleteAccountButton extends StatefulWidget {
7176
this.onDeleteFailed,
7277
this.variant = ButtonVariant.filled,
7378
this.showDeleteConfirmationDialog = false,
79+
this.deleteConfirmation,
7480
});
7581

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

94-
confirmed = await showCupertinoDialog<bool?>(
95-
context: context,
96-
builder: (context) {
97-
return UniversalAlert(
98-
onConfirm: pop(context, true),
99-
onCancel: pop(context, false),
100-
title: l.confirmDeleteAccountAlertTitle,
101-
confirmButtonText: l.confirmDeleteAccountButtonLabel,
102-
cancelButtonText: l.cancelButtonLabel,
103-
message: l.confirmDeleteAccountAlertMessage,
104-
);
105-
},
106-
);
100+
if (widget.deleteConfirmation != null) {
101+
confirmed = await widget.deleteConfirmation!(context);
102+
} else {
103+
confirmed = await showCupertinoDialog<bool?>(
104+
context: context,
105+
builder: (context) {
106+
return UniversalAlert(
107+
onConfirm: pop(context, true),
108+
onCancel: pop(context, false),
109+
title: l.confirmDeleteAccountAlertTitle,
110+
confirmButtonText: l.confirmDeleteAccountButtonLabel,
111+
cancelButtonText: l.cancelButtonLabel,
112+
message: l.confirmDeleteAccountAlertMessage,
113+
);
114+
},
115+
);
116+
}
107117
}
108118

109119
if (!(confirmed ?? false)) return;

0 commit comments

Comments
 (0)