diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index d07fa2765..895888917 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -896,6 +896,7 @@ "unVerifiedEmail": "Unverified email", "verifiedEmailReason": "You need to verify your email to contribute exercises", "verifiedEmailInfo": "A verification email was sent to {email}", + "verifiedEmailSent": "Email Sent", "@verifiedEmailInfo": { "placeholders": { "email": { diff --git a/lib/widgets/user/forms.dart b/lib/widgets/user/forms.dart index 1ed19191e..dceb862ed 100644 --- a/lib/widgets/user/forms.dart +++ b/lib/widgets/user/forms.dart @@ -38,6 +38,7 @@ class _UserProfileFormState extends State { final _form = GlobalKey(); final emailController = TextEditingController(); + bool _isVerifying = false; @override void initState() { @@ -101,23 +102,39 @@ class _UserProfileFormState extends State { ), if (!widget._profile.emailVerified) OutlinedButton( - onPressed: () async { - // Email is already verified - if (widget._profile.emailVerified) { - return; - } + // If _isVerifying is true, setting onPressed to null disables the button + onPressed: _isVerifying + ? null + : () async { + setState(() { + _isVerifying = true; + }); - // Verify - await context.read().verifyEmail(); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - AppLocalizations.of(context).verifiedEmailInfo(widget._profile.email), - ), - ), - ); - }, - child: Text(AppLocalizations.of(context).verify), + try { + // Verify + await context.read().verifyEmail(); + if (!context.mounted) return; + if (mounted) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text( + AppLocalizations.of( + context, + ).verifiedEmailInfo(widget._profile.email), + ), + ), + ); + } + } catch (e) { + // 'verify' button is enabled if error occurs + setState(() { + _isVerifying = false; + }); + } + }, + child: _isVerifying + ? Text(AppLocalizations.of(context).verifiedEmailSent) + : Text(AppLocalizations.of(context).verify), ), ElevatedButton( onPressed: () async {