Assignments are not expressions, and only expressions are allowed in this context I don't know how to fix this problem

private  fun uploadImageToFirebaswStorage(){
    if (selectedphotoUri = null) return
    val filename = UUID.randomUUID().toString()
     val ref = FirebaseStorage.getInstance().getReference("/images/$filename")

    ref.putFile(selectedphotoUri!!)
        .addOnSuccessListener {
            Log.d("Register","Successfully uploaded image: ${it.metadata?.path}")}
2

There are 2 best solutions below

0
CommonsWare On

selectedphotoUri = null is an assignment. Most likely, you want selectedphotoUri == null (two equals signs), which is the equality expression.

0
nPn On

Assuming you wanted to do an equality check as CommonsWare points out, another option would be to use a common Kotlin idiom involving let

val value = ...

value?.let { ... // execute this block if not null }

private  fun uploadImageToFirebaswStorage(){
    selectedphotoUri?.let {
        val filename = UUID.randomUUID().toString()
        val ref = FirebaseStorage.getInstance().getReference("/images/$filename")    
        ref.putFile(selectedphotoUri!!)
          .addOnSuccessListener {
              Log.d("Register","Successfully uploaded image: ${it.metadata?.path}")
          }
     }
}