Updating UIs with MutableState

With your Pizza model ready for use, you can begin incorporating UI state into your application. To get your bearings with how state behaves in Jetpack Compose, define a file-level property in PizzaBuilderScreen.kt to track selected toppings. Assign the pizza property’s initial value to include some toppings by default: pepperoni and pineapple on the whole pizza. After defining your pizza state, also update your ToppingsList composable to determine the placement of a topping based on the pizza property.

Listing 27.2  Declaring state (PizzaBuilderScreen.kt)

private var pizza =
    Pizza(
        toppings = mapOf(
            Topping.Pepperoni to ToppingPlacement.All,
            Topping.Pineapple to ToppingPlacement.All
        )
    ) ... @Composable ...

Get Android Programming: The Big Nerd Ranch Guide, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.