Home > Mobile >  Unresolved reference: ExposedDropdownMenuBox in Compose for Desktop
Unresolved reference: ExposedDropdownMenuBox in Compose for Desktop

Time:04-04

I need to implement a drop down menu for Windows App which is based on Compose for Desktop
For that I am trying to use ExposedDropdownMenuBox

But I am getting error:

Unresolved reference: ExposedDropdownMenuBox

Following is the code:

ExposedDropdownMenuBox(
    expanded = expanded,
    onExpandedChange = {
        expanded = !expanded
    }
) {
    // TextFeild implementation
}

And the file build.gradle.kts contains following:

import org.jetbrains.compose.compose
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    kotlin("jvm") version "1.6.10"
    id("org.jetbrains.compose") version "1.1.1"
}

group = "com.op.bgmi"
version = "1.0"

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

dependencies {
    implementation(compose.desktop.currentOs)
}

tasks.withType<KotlinCompile> {
    kotlinOptions.jvmTarget = "11"
}

compose.desktop {
    application {
        mainClass = "MainKt"
        nativeDistributions {
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
            packageName = "App"
            packageVersion = "1.0.0"
        }
    }
}

Am I missing something, please advice.
What is the correct approach to have drop down menu box in Compose for Desktop

CodePudding user response:

ExposedDropdownMenuBox is currently not available for Desktop.

You can check the location of the item in the AndroidX repository: it is located in androidMain folder, which makes it only available for the Android platform. It uses some Android-specific APIs under the hood, which makes it impossible to use from the desktop.

Perhaps it will be rewritten and made cross-platform before the `Experimental' annotation is removed, or there will be a separate implementation for Desktop in the future. You can follow updates here.

For now, you can use DropdownMenu as shown in this answer.

  • Related