1 回答

TA贡献1818条经验 获得超7个赞
可能存在项目小于分页大小的情况所以这里是代码
private var lastVisible: DocumentSnapshot? = null
private var isLastPage: Boolean = false
private var isDocEmpty: Boolean = false
var ref: Task<QuerySnapshot>? = null
if (lastVisible != null) {
ref = database.collection("app").document("data").collection("offers").orderBy("discount").startAfter(lastVisible).limit(paginationSize).get()
} else {
ref = database.collection("app").document("data").collection("offers").orderBy("discount").limit(paginationSize).get()
}
ref.addOnSuccessListener { documents ->
hideProgress()
isDocEmpty = documents.isEmpty
if (!isDocEmpty) {
lastVisible = documents.last()
isLastPage = documents.size() < paginationSize
}
isLoading = false
}
.addOnFailureListener { exception ->
Log.w("TAG", "Error getting documents: ", exception)
isLoading = false
hideProgress()
}
我希望这会帮助你。
添加回答
举报