May 2022
Intermediate to advanced
688 pages
20h 12m
English
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 ...Read now
Unlock full access