On this article, you’ll learn to create a convertible listing in Jetpack Compose!
We’d like an information supply that may act as our sole Supply of Reality
Within the above code, we’ve created an enum class containing person sorts; you need to use an information layer or every other class that fits your wants.
Then we create the naked bones of our listing merchandise.
- First, we create an mixture operate that holds our remaining code
- The code floor, though not at the moment helpful, can be utilized for additional customization
- Column structure with switchable modifier (this does all of the trick) and its job is to set the column’s convertible state to True or False and replace OnValueChanged the strategy tells us when the information modifications
- The field incorporates the picture and the examine icon, we used the field right here as a result of one of many widgets should overlap
- A variable container that holds a boolean worth for visibility meant to animate the examine icon and we declare that worth true when any merchandise is chosen
- AnimateVisibility modal is boxed with jetpack compose and it helps to animate the article, it takes a show parameter with each enter and output animation sorts
- A textual content can synthesize
With that, we transfer on to the subsequent step by creating an Merchandise group; that is the place we are going to place our Lazy Row.
That is only a composable operate that may generate every merchandise within the dataset individually.
In case of used
To make use of the operate we created, we’ve to name the Merchandise Pool we created within the android exercise of one other composable operate:
That is all we have to create a convertible listing merchandise in Jetpack Compose.
Observe: Though I used memorySavable right here for instance however in manufacturing code or actual use case! Please change state to viewModel
Beneath is an illustration of what we intend to realize, though I made some modifications to the app within the video you need to get the overall concept.