Skip to content
53 changes: 37 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,43 @@ class _UserProfileFormState extends State<UserProfileForm> {
),
if (!widget._profile.emailVerified)
OutlinedButton(
onPressed: () async {
// Email is already verified
if (widget._profile.emailVerified) {
return;
}
style: OutlinedButton.styleFrom(
Comment thread
pankaj-basnet marked this conversation as resolved.
Outdated
// Applying the "Darker background" when disabled
disabledBackgroundColor: Colors.grey.shade300,
side: BorderSide(
color: _isVerifying ? Colors.grey : Colors.green,
),
),
// 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) {
Comment thread
pankaj-basnet marked this conversation as resolved.
setState(() {
_isVerifying = false;
});
}
},
child: _isVerifying ? const Text("Email sent") : Text(AppLocalizations.of(context).verify),
Comment thread
pankaj-basnet marked this conversation as resolved.
Outdated
),
ElevatedButton(
onPressed: () async {
Expand Down