3

I am new in Jetpack Compose(JC). I started JC and used card but it shows me an error and recommend me to add this annotation @OptIn(ExperimentalMaterial3Api::class).

Also showing this message This material API is experimental and is likely to change or to be removed in the future. My Question that if this is experimental and might have changes in future what is the normal and stable way to use card in jetpack compose Material3?

What does this annotation actually means and what if I don't want to use experimental or thing which is not stable.

As I also find that Material3 is stable.

https://material.io/blog/material-3-compose-stable

Clarify me if you think that I don't understand this correctly or provide the appropriate fix.

Thx!

Mohammad Taqi
  • 161
  • 2
  • 8
  • There are two Card composables in Material3, one has `onClick` argument and is experimental - that's the one you are talking about, the other doesn't have onClick argument and is not experimental. The annotation means pretty much what it says, the api may change in the future. If you don't want to use experimental stuff, you can find stable alternative or implement it yourself. – Jan Bína Mar 22 '23 at 11:49
  • https://www.linkpicture.com/q/Untitled_508.png. I used a card with no onClick arguments still it's tell me to add that annotation. – Mohammad Taqi Mar 22 '23 at 12:41
  • Which version are you using? It shouldn't be experimental since 1.0.0-alpha15. https://android-review.googlesource.com/c/platform/frameworks/support/+/2138161 – Jan Bína Mar 22 '23 at 12:55
  • I am using alpha11. 'androidx.compose.material3:material3:1.0.0-alpha11' – Mohammad Taqi Mar 22 '23 at 13:04
  • 1
    Yeah then you should probably upgrade. Either to latest stable version `1.0.1`, or latest alpha `1.1.0-alpha08` – Jan Bína Mar 22 '23 at 13:10
  • Yes it worked for Card without onClick. But do you know what is the alternative for the Card with onclick in Compose bcz Material 3 is stable now and the Card is in experiment state that's strange! – Mohammad Taqi Mar 22 '23 at 13:44
  • I'd just use it. If you look it the implementation, Card is just Surface with customized color, shape and elevation. And card with onClick only passes the onClick to that Surface (which is not experimental!). I don't know why the card itself is experimental tbh. – Jan Bína Mar 22 '23 at 13:56
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/252709/discussion-between-mohammad-taqi-and-jan-bina). – Mohammad Taqi Mar 23 '23 at 06:03

1 Answers1

-2
buildFeatures {
    compose true
    kotlinOptions {
        freeCompilerArgs += [
                "-opt-in=kotlin.ExperimentalUnsignedTypes",
                "-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
                "-opt-in=kotlinx.coroutines.InternalCoroutinesApi",
                "-opt-in=androidx.compose.animation.ExperimentalAnimationApi",
                "-opt-in=androidx.compose.ExperimentalComposeApi",
                "-opt-in=androidx.compose.material.ExperimentalMaterialApi",
                "-opt-in=androidx.compose.runtime.ExperimentalComposeApi",
                "-opt-in=androidx.compose.ui.ExperimentalComposeUiApi",
                "-opt-in=androidx.compose.material3.ExperimentalMaterial3Api",
                "-opt-in=coil.annotation.ExperimentalCoilApi",
                "-opt-in=kotlinx.serialization.ExperimentalSerializationApi",
                "-opt-in=com.google.accompanist.pager.ExperimentalPagerApi",
                "-opt-in=com.google.accompanist.navigation.material.ExperimentalMaterialNavigationApi"
        ]
    }
}
  • Nowhere in this chunk of text is explained the reason of *why* the annotation is needed, what it does, and what consequences or side effects is produces. You're merely choosing to include them all with no knowledge of what they do. Please don't do this unless you know what you're doing. – Martin Marconcini May 11 '23 at 11:40
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 11 '23 at 11:54
  • That just hides the fact you are using experimental. Why do we need any experimental widgets when M3 is now stable? – shawnlg Aug 30 '23 at 18:16