在这里,我正在使用快照获取当前用户数据。user 是一个数据类,它包含几个变量和一个可变的字符串列表。在这里,我从用户那里获取输入并创建一个新的可变字符串列表,首先从当前用户可变列表中放入数据,然后将用户输入,然后在当前用户可变列表的位置更新这个可变列表。问题:可变列表只显示一个字符串(最近添加了一个)并且之前的所有字符串都没有存储
val todoTitle = edToEditTitle.text.toString() //getting data from user
var mutableList = mutableListOf<String>() //making a new mutable list
if(todoTitle.isNotEmpty()){ //if data entered by user is not empty
auth.currentUser?.let {
FirebaseFirestore.getInstance()
.collection("users")
.document(it.uid)
.get()
.addOnCompleteListener { task ->
if (task.isSuccessful) {
val product: user? = task.result.toObject(user::class.java) //getting the current data snapshot for current user(which contains a mutable list of strings)
Log.d(ContentValues.TAG, "onComplete: $product")
if (product != null) {
for(i in product.list!!){ //if current users mutable list is not empty
mutableList.add(i); //add contents to new mutable list
}
}
} else {
Log.e(ContentValues.TAG, "onComplete: ", task.exception)
}
}
}
mutableList.add(todoTitle); //add new input also
db.collection("users").document(auth.currentUser!!.uid).update("list",mutableList) //update current users list