I want to fetch data from room table using a search query and present the result in LazyColumn instead of the someList I present there.
In other words, how to implement search function using compose from room table?
//Getting the list from room and presenting it in lazy column
val someList by mainViewModel.getSomeItems.collectAsState(initial = emptyList())
LazyColumn(
verticalArrangement = Arrangement.spacedBy(8.dp),
modifier = Modifier
.fillMaxSize()
.padding(16.dp)
) {
itemsIndexed(items = someList) { itemIndex, item ->
//not really important to the question
item.currentInventory?.let {
MainScreenItemRow(
itemId = item.id,
itemNumber = item.itemNumber,
itemDescription = item.itemDescription,
currentInventory = it,
)
}
}
}
} // end of lazy
I want to use DAO query and present the result list if query matches to one of the items in "someList".
@Query("SELECT * from someList WHERE id LIKE :search OR itemNumber LIKE :search OR itemDescription LIKE :search")
fun searchInventory (search: String): Flow<List<SomeList>>
How can I insert the query results into a list and present it in lazy column?