uploadImage method

Future<Null> uploadImage ()

Uploads the image requested by the user.

Implementation

Future<Null> uploadImage() async {
  print("uploading image"); //todo: remove debug print
  int random = new Random().nextInt(100000);
  StorageReference ref = FirebaseStorage.instance
      .ref()
      .child("/partyImages/party_image_$random.jpg");
  print(localImageFile);
  StorageFileUploadTask uploadTask = ref.putFile(localImageFile);
  Duration timeoutDuration = new Duration(seconds: 30);
  try {
    UploadTaskSnapshot task = await uploadTask.future
        .timeout(timeoutDuration,
            onTimeout: () =>
                throw new TimeoutException('TIMEOUT', timeoutDuration))
        .catchError(() => throw new Exception('UPLOAD ERROR'));
    Uri downloadUrl = task.downloadUrl;
    imageUrl = downloadUrl.toString();
  } on TimeoutException {
    print(TimeoutException);
  } on Exception catch (e) {
    print('Image upload exception, $e');
  }
}