updateEmail method
Implementation
Future<bool> updateEmail(String newEmail, String password) async {
final user = _auth.currentUser;
if (user == null) {
print('No user is currently signed in.');
return false;
}
try {
// Re-authenticate the user
final credential = EmailAuthProvider.credential(email: user.email!, password: password);
await user.reauthenticateWithCredential(credential);
// Update email
await user.updateEmail(newEmail);
await user.reload();
return true;
} catch (e) {
print(e.toString());
return false;
}
}