27
UI State in Jetpack Compose

Coda Pizza is off to a good start. In the last chapter, you built out a scrollable list, created a composable to act as the cell for toppings, and set up the screen’s layout, including an order button at the bottom of the page. But your app is missing something: Users cannot interact with it (other than scrolling the list of toppings). If users press a checkbox, it does not change from checked to unchecked or vice versa.

This is not what you are used to with framework views. Think back to CriminalIntent, where you used a CheckBox view to track whether a crime was solved. As soon as you added the checkbox to your UI, it responded to click events by toggling its state, with no additional code needed.

In this chapter, you will learn why your current code does not respond to user inputs, and you will see how to incorporate UI state into your composables. By the end of this chapter, Coda Pizza will let users place and remove toppings on their pizzas. Pressing either the checkbox or the topping’s cell will toggle whether the topping is on the pizza. You will also update the PLACE ORDER button to include the price for the pizza based on the number of toppings.

When you finish with this chapter, Coda Pizza will look like Figure 27.1.

Figure 27.1  Coda Pizza, now with state

Coda Pizza, now with state

In the next chapter, you will go a step further and display a dialog to ask the user where they want their topping to be placed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.103.227