calling a java FileDialog works great, unless I'm ...
# compose-desktop
j
calling a java FileDialog works great, unless I'm in a TextField.
Copy code
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
Copy code
//class field
val saveFileName = mutableStateOf(TextFieldValue())

TextField(
    value = saveFileName.value,
    onValueChange = { saveFileName.value = it },
)
o
please report an issue with full reproducer
i
Regardless the issue, you should use:
Copy code
val saveFileName = remember { mutableStateOf(TextFieldValue()) }
Otherwise Compose will create a new state on every recomposition
o
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
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
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
I upgraded from the IDE default compose 4 to compose 5 and the problem vanished 🙂