kotlin.NotImplementedError: An operation is not implemented: not implemented AlertDialog

kotlin.NotImplementedError: An operation is not implemented: not implemented AlertDialog

我正在尝试使用 kotlin 的桌面组合进行一些练习,当我尝试实现 AlertDialog 元素时,我遇到了这个异常:

Exception in thread "AWT-EventQueue-0 @coroutine#3" kotlin.NotImplementedError: An operation is not implemented: not implemented

我正在尝试的代码 运行 :

fun main() {
    var text = mutableStateOf(0F)
    var num = mutableStateOf("a")
    Window(
        size = IntSize(500, 500),
        title = num.value,
        menuBar = MenuBar(
            Menu(
                name = "Test",
                MenuItem(
                    name = "Dodaj random",
                    onClick = {
                        text.value = text.value + Random.nextFloat()
                        if (text.value > 1F) {
                            text.value = 0F
                            num.value += "a"
                        }
                    },
                    shortcut = KeyStroke(Key.A)
                ),
                MenuItem(
                    name = "Exit",
                    onClick = {
                        AppManager.exit()
                    },
                    shortcut = KeyStroke(Key.L)
                )
            )
        )
    ) {

        MaterialTheme {
            Column(Modifier.fillMaxSize(), Arrangement.spacedBy(12.dp)) {
                LinearProgressIndicator(text.value.toFloat(), modifier = Modifier.align(Alignment.CenterHorizontally))
                val openDialog = remember { mutableStateOf(false) }
                Button(
                    onClick = {
                        openDialog.value = true
                    }) {
                    Text("Click me!")
                }
                if (openDialog.value) {
                    AlertDialog(
                        onDismissRequest = { openDialog.value = false },
                        title = { Text("Dialog title") },
                        text = { Text("Here is a text") },
                        confirmButton = {
                            Button(
                                onClick = {
                                    openDialog.value = false
                                }
                            ) { Text("Confirm butt") }
                        },
                        dismissButton = {
                            Button(
                                onClick = {
                                    openDialog.value = false
                                }
                            ) { Text("Diss butt") }
                        }
                    )
                }
                Button(
                    onClick = {
                        text.value += 0.1F
                        if (text.value > 1F) {
                            text.value = 0F
                            num.value += "a"
                        }
                    },
                    modifier = Modifier.align(Alignment.CenterHorizontally)
                ) {
                    Text(text.value.toString())
                }

                Button(
                    onClick = {
                        num.value += "a"
                    },
                    modifier = Modifier.align(Alignment.CenterHorizontally)
                ) {
                    Text(num.component1())
                }


            }
        }
    }
}

仅当我尝试单击“单击我”按钮时出现此异常,其他按钮工作正常。

我的导入

import androidx.compose.desktop.AppManager
import androidx.compose.desktop.Window
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.Button
import androidx.compose.material.LinearProgressIndicator
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.KeyStroke
import androidx.compose.ui.window.Menu
import androidx.compose.ui.window.MenuBar
import androidx.compose.ui.window.MenuItem
import kotlin.random.Random

您的问题似乎与 this github 问题有关。

要解决它,只需将 compose 依赖项更新为 0.2.0-build132。

我的 build.gradle 的完整示例以及正确的版本:

import org.jetbrains.compose.compose

plugins {
    kotlin("jvm") version "1.4.20"
    id("org.jetbrains.compose") version "0.2.0-build132"
}

repositories {
    jcenter()
    maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}

dependencies {
    implementation(compose.desktop.currentOs)
}

compose.desktop {
    application {
        mainClass = "MainKt"
    }
}