I have a list with a few records. Every record has a city, country, date and id (its primary key). In dao, then repository I have function which accepts id. Finally display list it’s fine, but problem is when I click the record and display modal with this data. Id records is incorrect and the city name, country name etc. is incorrect.
Repository:
override suspend fun showDetailsTrip(id: Int) = db.dao().showDetailsTrip(id)
viewModel:
private fun showDetails(id: Int) {
_uiState.update { it.copy(showBottomSheet = true) }
viewModelScope.launch {
repository.showDetailsTrip(id = id)
}
}
Screen:
LazyColumn(
modifier = Modifier
.padding(MaterialTheme.whereNowSpacing.space16)
.fillMaxSize(),
verticalArrangement = Arrangement.spacedBy(MaterialTheme.whereNowSpacing.space32),
horizontalAlignment = Alignment.CenterHorizontally
) {
items(items = state.tripList, key = { id -> id.id }) { list ->
WhereNowDetailsTile(
city = list.cityFrom,
country = list.countryFrom,
date = list.date,
timeTravel = LocalDate.now(),
countDays = 0,
onDeleteClick = { uiIntent(TripListUiIntent.OnDeleteTrip(list.id)) },
**onClick = { uiIntent(TripListUiIntent.ShowTripDetails(list.id)) }**
)
if (state.showBottomSheet) {
ModalBottomSheet(
onDismissRequest = { uiIntent(TripListUiIntent.HideTripDetails) },
contentColor = MaterialTheme.colorScheme.error,
sheetState = sheetState,
tonalElevation = 72.dp,
dragHandle = {}
) {
Column(
modifier = Modifier
.background(MaterialTheme.colorScheme.background)
.padding(vertical = MaterialTheme.whereNowSpacing.space24)
.padding(horizontal = MaterialTheme.whereNowSpacing.space16)
.verticalScroll(rememberScrollState())
) {
Text(
modifier = Modifier
.align(Alignment.CenterHorizontally),
text = "Wylot",
style = MaterialTheme.typography.titleLarge.copy(MaterialTheme.colorScheme.primary)
)
HorizontalDivider(
modifier = Modifier.padding(
vertical = MaterialTheme.whereNowSpacing.space16,
horizontal = MaterialTheme.whereNowSpacing.space8
)
)
**WhereNowTextField(
label = "City",
value = state.tripList.find { it.id == list.id }?.cityFrom ?: ""
)**
```