I want to insert some data into Firebase. for that, I have a non-composable function and in that function, I'd like to call Toast.makeText . . in the .addOnSuccessListener part. However, there's no way for me to get the context that should be in the Toast.makeText statement
fun saveActivityToFB(
answer: String,
question: String,
id: String
) {
var db: DatabaseReference = Firebase.database.reference
val ques = Question(answer, question)
db.child("activity").child("test").child(id).setValue(ques)
.addOnSuccessListener {
Log.d("FB", "OK")
//problems with context here!!
Toast.makeText(context, "Successfully Added to FB", Toast.LENGTH_SHORT).show()
}
.addOnFailureListener {
Log.d("FB", "Not inserted into FB")
}
}
I know that in order to display Toast from composable function, I should get context as:
val context = LocalContext.current
But have no idea how to get the context in this case.
saveActivityToFBitself, you can passContextas another argument in this function.