https://kotlinlang.org logo
Title
j

Joey Heck

08/03/2021, 8:42 PM
calling a java FileDialog works great, unless I'm in a TextField.
val fileDialog = FileDialog(window.window)
fileDialog.isVisible = true
triggers
Exception in thread "AWT-EventQueue-0" kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for CancellableContinuation(DispatchedContinuation[FlushCoroutineDispatcher@8e8a808, Continuation at androidx.compose.foundation.gestures.TapGestureDetectorKt.awaitChannelUpOrCancel(TapGestureDetector.kt:275)@45a19ee9]){Completed}@50fcdf16. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
The textfield
//class field
val saveFileName = mutableStateOf(TextFieldValue())

TextField(
    value = saveFileName.value,
    onValueChange = { saveFileName.value = it },
)
o

olonho

08/04/2021, 5:55 AM
please report an issue with full reproducer
i

Igor Demin

08/04/2021, 8:04 AM
Regardless the issue, you should use:
val saveFileName = remember { mutableStateOf(TextFieldValue()) }
Otherwise Compose will create a new state on every recomposition
o

olonho

08/04/2021, 9:55 AM
seems pretty much every usage of
mutableStateOf
without
remember
in composable function is an error. @alexey.tsvetkov maybe it's worth an IDE inspection?
👍 1
j

Joey Heck

08/04/2021, 2:44 PM
thank you for pointing out the remember. I will change that (I was having a weird performance issue, and thought it might be my mutable state). I thought if it was at the class level, it didn't need to be remember.
i

Igor Demin

08/04/2021, 2:49 PM
If your mutableStateOf is inside class, not inside Composable function then indeed, remember isn't needed. I didn't notice the comment :)
The cause of crash is still a mistery. It would be helpful if you provide a minimal reproducer.
If your mutableStateOf is inside class, not inside Composable function then indeed, remember isn't needed.
But the instance of class itself should be in remember too
j

Joey Heck

08/04/2021, 3:42 PM
I upgraded from the IDE default compose 4 to compose 5 and the problem vanished 🙂