Hyalunar
Hyalunar

Reputation: 124

Avoid ExperimentalMaterial3Api-OptIn in a Kotlin Android-App

Using Jetpack Compose and Android Studio, I have been trying to learn developing apps.

I wanted to have a Text Widget display exactly what was typed into a text field.

When building this, following the answer of this question (Custom class for holding multiple states in Jetpack Compose), I build up some code which seemingly requires an Experimental Material3 Api.

I don't know which part of my code needs the experimental API and I would like to avoid this.

I tried with the following code

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun NameGreeter() {
    var content by remember {
        mutableStateOf("Editable Text")
    }
    Column {
        Text(text = content)
        TextField(value = content, onValueChange = {
            content = it
        })
    }
}

and the compiler prompted me with an error message which would inform me that this function needs experimental API support of type "class".

Where do I see which classes really are part of the experimental API and do you know alternatives to avoid them?

Upvotes: 1

Views: 1115

Answers (1)

ΓDΛ
ΓDΛ

Reputation: 11080

Where do I see which classes really are part of the experimental API and do you know alternatives to avoid them?

He stated the risk of the relevant structure in the documentation.

@RequiresOptIn(message = "This material API is experimental and is likely to change or to be removed in the future.")
@Retention(value = AnnotationRetention.BINARY)
annotation ExperimentalMaterial3Api

This material API is experimental and is likely to change or to be removed in the future.

You can see all experimental versions by searching here.

Sample 1.0.0-beta01 version. If you search for "ExperimentalMaterial3Api" you can see it.

Upvotes: 0

Related Questions