I have a lazy vertical grid, and the items are focusable, when the item is clicked it navigates to another screen, when the user presses the back button and comes back to the screen with lazy vertical grid, i want the item that was focused to get focus again. is it possible to even do this? i tried many different ways but i get the same error:
error: FocusRequester is not initialized. Here are some possible fixes:
1. Remember the FocusRequester: val focusRequester = remember { FocusRequester() }
2. Did you forget to add a Modifier.focusRequester() ?
3. Are you attempting to request focus during composition? Focus requests should be made in
response to some event. Eg Modifier.clickable { focusRequester.requestFocus() }
this is not the exact code i have, but its the same except some stylings:
LazyVerticalGrid(columns = GridCells.Fixed(4)) {
itemsIndexed(items = listOf(1,2,3,4,5)) { index, item ->
val focusRequester = remember {
FocusRequester()
}
Column(
modifier = Modifier
.onFocusChanged {
// ...
}
.focusRequester(focusRequester)
.clickable {
// navigate to some page
}
) {
Text(text = item.toString())
}
if (item == 3) focusRequester.requestFocus()
}
}