Android Programming: The Big Nerd Ranch Guide, 5th Edition
by Bryan Sills, Brian Gardner, Kristin Marsicano, Chris Stewart
Defining Your UI State
The first step in adding state to a Compose application is to define the models you will use to store it. For Coda Pizza, you need a place to hold the state of which toppings are selected. Create a new file called Pizza.kt in the com.bignerdranch.android.codapizza.model package. In this file, create a new data class called Pizza.
Give your data class one property: the toppings on the pizza, a Map<Topping, ToppingPlacement>. If a topping is present on the pizza, it will be added to this map as a key. The value will be the topping’s position on the pizza. If a topping is not on the pizza, it will not have an entry in this map.
Listing 27.1 The Pizza class (Pizza.kt)
data class Pizza(
val toppings: Map<Topping, ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access