Skip to content
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
1 change: 1 addition & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
49 changes: 33 additions & 16 deletions lib/widgets/user/forms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class _UserProfileFormState extends State<UserProfileForm> {
final _form = GlobalKey<FormState>();

final emailController = TextEditingController();
bool _isVerifying = false;

@override
void initState() {
Expand Down Expand Up @@ -101,23 +102,39 @@ class _UserProfileFormState extends State<UserProfileForm> {
),
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<UserProvider>().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<UserProvider>().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 {
Expand Down