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

851 Views Asked by At

I was trying to practice a little with desktop compose for kotlin and when i was trying to implement AlertDialog element I got this exception:

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

The code that im trying to run :

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())
                }


            }
        }
    }
}

Only when I'm trying to click on the "Click me" button I'm getting this exception other buttons works perfectly.

My imports

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
1

There are 1 best solutions below

4
On BEST ANSWER

Your issue seems related to this github issue.

To solve it simply update compose dependency to 0.2.0-build132.

Complete example of my build.gradle with the correct versions:

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"
    }
}