error handling on image upload

This commit is contained in:
shilangyu 2020-10-24 19:58:38 +02:00
parent a41e5c19c3
commit 93c0e883d3
1 changed files with 16 additions and 9 deletions

View File

@ -73,6 +73,7 @@ class CreatePost extends HookWidget {
);
uploadPicture() async {
try {
final pic = await imagePicker.getImage(source: ImageSource.gallery);
// pic is null when the picker was cancelled
if (pic != null) {
@ -84,6 +85,12 @@ class CreatePost extends HookWidget {
pictrsDeleteToken.value = upload.files[0];
urlController.text =
pathToPictrs(selectedInstance.value, upload.files[0].file);
}
// ignore: avoid_catches_without_on_clauses
} catch (e) {
scaffoldKey.currentState
.showSnackBar(SnackBar(content: Text('Failed to upload image')));
} finally {
imageUploadLoading.value = false;
}
}