I am basically trying to show an alert dialog when a user try to add a document or upload an image to firestore cloud/firebase storage. I tried that with try and catch blocks as well as .catchError() but it did not work, and it basically do this after getting an internet connection. what i want to do is to show an alert dialog and cancel the process even the user gets a connection back (he have to repeat the process of uploading again). here is a sample of my code:
this is for picking and uploading an image:
Future _getImage(bool isCamera) async {
var pickedImage;
try {
if (isCamera)
pickedImage =
await picker.getImage(source: ImageSource.camera, imageQuality: 20);
else
pickedImage = await picker.getImage(
source: ImageSource.gallery, imageQuality: 20);
if (pickedImage != null) {
_uploadAndSetUrl(File(pickedImage.path));
}
} catch (e) {
print('error here');
}
}
Future _uploadAndSetUrl(File image) async {
try {
_uploadingStatus(true);
StorageUploadTask uploadTask = _bookImageRef.putFile(image);
StorageTaskSnapshot taskSnapshot = await uploadTask.onComplete;
String downloadAddress = await _bookImageRef.getDownloadURL();
_uploadingStatus(false);
setState(() {
_imageUrl = downloadAddress;
});
print(_imageUrl);
} on PlatformException catch (e) {
print('error: $e');
} catch (e) {
print('No image added');
}
}
and there is another method for adding a document into firestore cloud. is there any way to do that?
thank you in advance!