diff --git a/packages/firebase_ui_auth/lib/src/actions.dart b/packages/firebase_ui_auth/lib/src/actions.dart index 31045651..e92a0780 100644 --- a/packages/firebase_ui_auth/lib/src/actions.dart +++ b/packages/firebase_ui_auth/lib/src/actions.dart @@ -2,6 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/material.dart'; import 'package:firebase_ui_auth/firebase_ui_auth.dart'; @@ -15,6 +16,8 @@ import 'package:firebase_ui_auth/firebase_ui_auth.dart'; /// - [SMSCodeRequestedAction] /// - [EmailVerifiedAction] /// - [ForgotPasswordAction] +/// = [AccountDeletedAction] +/// - [DisplayNameChangedAction] abstract class FirebaseUIAction { /// Looks up an instance of an action of the type [T] provided /// via [FirebaseUIActions]. @@ -84,6 +87,32 @@ class AuthCancelledAction extends FirebaseUIAction { AuthCancelledAction(this.callback); } +/// {@template ui.auth.actions.account_deleted} +/// An action that is being called when user has deleted their account. +/// {@endtemplate} +class AccountDeletedAction extends FirebaseUIAction { + /// A callback that is being called when user has deleted their account. + final void Function(BuildContext context, User user) callback; + + /// {@macro ui.auth.actions.account_deleted} + AccountDeletedAction(this.callback); +} + +/// {@template ui.auth.actions.display_name_changed} +/// An action that is being called when user has changed their display name. +/// {@endtemplate} +class DisplayNameChangedAction extends FirebaseUIAction { + /// A callback that is being called when user has changed their display name. + final void Function( + BuildContext context, + String? oldName, + String newName, + ) callback; + + /// {@macro ui.auth.actions.display_name_changed} + DisplayNameChangedAction(this.callback); +} + /// {@template ui.auth.actions.flutter_fire_ui_actions} /// An inherited widget that provides a list of actions down the widget tree. /// {@endtemplate} diff --git a/packages/firebase_ui_auth/lib/src/widgets/delete_account_button.dart b/packages/firebase_ui_auth/lib/src/widgets/delete_account_button.dart index 58bb037b..d3ad5f6f 100644 --- a/packages/firebase_ui_auth/lib/src/widgets/delete_account_button.dart +++ b/packages/firebase_ui_auth/lib/src/widgets/delete_account_button.dart @@ -15,6 +15,34 @@ typedef SignInRequiredCallback = Future Function(); /// {@template ui.auth.widgets.delete_account_button} /// A button that triggers the deletion of the user's account. +/// +/// If you want to perform an action after the account is deleted, you can +/// use [AccountDeletedAction]. +/// +/// Example usage: +/// ```dart +/// ProfileScreen( +/// actions: [ +/// AccountDeletedAction((context, user) { +/// // Do something after the account is deleted. +/// }), +/// ], +/// ); +/// ``` +/// +/// or +/// +/// ```dart +/// FirebaseUIActions( +/// actions: [ +/// AccountDeletedAction((context, user) { +/// // Do something after the account is deleted. +/// }), +/// ], +/// // MyCustomScreen should use DeleteAccountButton internally. +/// child: MyCustomScreen(), +/// ) +/// ``` /// {@endtemplate} class DeleteAccountButton extends StatefulWidget { /// {@macro ui.auth.auth_controller.auth} @@ -55,7 +83,13 @@ class _DeleteAccountButtonState extends State { }); try { + final user = auth.currentUser!; await auth.currentUser?.delete(); + + FirebaseUIAction.ofType(context)?.callback( + context, + user, + ); await FirebaseUIAuth.signOut(context: context, auth: auth); } on FirebaseAuthException catch (err) { if (err.code == 'requires-recent-login') { diff --git a/packages/firebase_ui_auth/lib/src/widgets/editable_user_display_name.dart b/packages/firebase_ui_auth/lib/src/widgets/editable_user_display_name.dart index 9e0d41f8..10fd4dab 100644 --- a/packages/firebase_ui_auth/lib/src/widgets/editable_user_display_name.dart +++ b/packages/firebase_ui_auth/lib/src/widgets/editable_user_display_name.dart @@ -8,6 +8,7 @@ import 'package:flutter/cupertino.dart'; import 'package:firebase_ui_localizations/firebase_ui_localizations.dart'; import 'package:flutter/material.dart'; +import '../actions.dart'; import 'internal/subtitle.dart'; /// {@template ui.auth.widgets.editable_user_display_name} @@ -15,6 +16,20 @@ import 'internal/subtitle.dart'; /// If the user name is not provided by neither of the providers, /// a text field is being shown. Otherwise, a user name is rendered with the /// edit icon. +/// +/// If you want to perform an action after display name is changed, you can +/// use [DisplayNameChangedAction]. +/// +/// Example usage: +/// ```dart +/// ProfileScreen( +/// actions: [ +/// DisplayNameChangedAction((context, oldName, newName) { +/// // Do something with the new name. +/// }), +/// ], +/// ); +/// ``` /// {@endtemplate} class EditableUserDisplayName extends StatefulWidget { /// {@macro ui.auth.auth_controller.auth} @@ -57,6 +72,12 @@ class _EditableUserDisplayNameState extends State { await auth.currentUser?.updateDisplayName(ctrl.text); await auth.currentUser?.reload(); + + FirebaseUIAction.ofType(context)?.callback( + context, + displayName, + ctrl.text, + ); } finally { setState(() { _editing = false;