Jetpack Compose ModalBottomSheetLayout IllegalArgumentException: The initial value must have an associated anchor

For my case, I show ModalBottomSheetLayout, click on an item to perform compose navigation to another screen. When I returned to the current screen, ocassionally I get IllegalArgumentException (not everytime). I suspect I modified the data, which caused compose render in ModalBottomSheetLayout and cause the error (maybe a bug).

I try to set a min height but it doesn't seems to work.

val modalBottomSheetState = rememberModalBottomSheetState(ModalBottomSheetValue.Hidden)ModalBottomSheetLayout(    sheetState = modalBottomSheetState,    sheetContent = {        val albums by viewModel.albumsFlow.collectAsState(initial = emptyList())        Box(            Modifier                .fillMaxWidth()                .defaultMinSize(minHeight = 100.dp)) {            // content        }    })

My final solution is call modalBottomSheetState.hide() before I navigate away, so that ModalBottomSheetLayout is hidden when returned.

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.