This is my function inside viewModel class:
fun updateMenu(menu: Menu) = viewModelScope.launch {
menuDao.update(menu) // updating menu to database
total = hitungTotal() // calculate all subtotal to total
}
private fun hitungTotal(): Int {
var sum = 0
menuList.value?.apply {
for (i in this.indices) sum += this.get(i).subTotal
}
return sum
}
I want hitungTotal()
function to be executed after the database is updated. How to achieve this?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…