Create TableSession.kt — the scanned table
In the code column — TableSession.kt. Small but important: it holds the scanned table as a StateFlow, so any screen can observe it. setTable("table:12") strips the table: prefix and keeps 12.
Wire it into Koin — one single, so the whole app shares the same table:
// feature/scan/di/ScanModule.kt
val scanModule = module {
single { TableSession() }
}
// and add scanModule to the PicaApplication modules(...) list
Now recall lesson 8a: there AuthViewModel.logout() kept only repository.logout(). The real version also clears the table on logout — a new user sits somewhere else:
fun logout(onLoggedOut: () -> Unit) = viewModelScope.launch {
repository.logout()
tableSession.clearTable() // ← now that TableSession exists
onLoggedOut()
}
// authModule: viewModel { AuthViewModel(get(), get()) } // + TableSession
And the cart finally gets a real table. In lesson 9 it was placeOrder(..., tableNumber = null); now:
val table = tableSession.tableNumber.value
orderRepository.placeOrder(items, table) // table_number rides into POST /orders
Tip. Why is
TableSessiona separatesingle, not just a field on the cart? Because the table is shared context:ScanScreenreads it, the cart and the checkout use it. One shared source (a single) means everyone sees the same value, with no threading it through navigation.