updateEmail method
Change Profile Photo
Change E-Mail
Implementation
// Future<void> uploadProfilePhoto({
// required XFile image,
// }) async {
// await _handleAccountOperation(
// operationName: 'Changing profile photo',
// successMessage: 'Your profile photo has been updated!',
// closeOverlaysOnSuccess: true,
// authOperation: () async {
// String filePath = 'profile_pictures/${FirebaseAuth.instance.currentUser!.uid}/profile_picture.jpg';
// Reference storageReference = FirebaseStorage.instance.ref().child('images').child(filePath);
// final metadata = SettableMetadata(
// contentType: 'profile_picture/jpg',
// customMetadata: {'profile_pictures': image.path},
// );
// if (kDebugMode) {
// print('Uploading depending on if its web');
// }
// UploadTask uploadTask;
// if (kIsWeb) {
// uploadTask = storageReference.putData(await image.readAsBytes(), metadata);
// } else {
// //TODO: Check if this works on mobile
// uploadTask = storageReference.putFile(File(image.path), metadata);
// }
// await uploadTask;
// if (kDebugMode) {
// print('getDownloadURL');
// }
// final String imageUrl = await storageReference.getDownloadURL();
// await FirebaseFirestore.instance.collection('users').doc(FirebaseAuth.instance.currentUser!.uid).update({
// 'imageUrl': imageUrl,
// });
// if (kDebugMode) {
// print('image URL: $imageUrl');
// }
// await FirebaseAuth.instance.currentUser!.updatePhotoURL(imageUrl);
// },
// );
// }
///
/// Change E-Mail
///
Future<void> updateEmail({
required String newEmail,
}) async {
await _handleAccountOperation(
operationName: 'Updating E-Mail',
successMessage:
'Your E-Mail changed to: ${FirebaseAuth.instance.currentUser!.email}!',
closeOverlaysOnSuccess: true,
authOperation: () async {
await FirebaseAuth.instance.currentUser!
.updateEmail(newEmail);
await FirebaseAuth.instance.currentUser!
.sendEmailVerification();
await FirebaseFirestore.instance
.collection('users')
.doc(FirebaseAuth.instance.currentUser!.uid)
.update({'email': newEmail});
},
);
}