Jetpack Compose 1.7 Essentials was published on October 28, 2024.
The current revision is 1.0. The revision of your book can be found on the copyright page at the start of the book.
The code example in this section should read as follows:
.
.
@Composable
fun DemoScreen(modifier: Modifier = Modifier) {
Column {
MyTextField()
FunctionA()
}
}
.
.
@Composablefun FunctionA() {
var switchState by remember { mutableStateOf(true) }
val onSwitchChange = { value : Boolean ->
switchState = value
}
FunctionB(
switchState = switchState,
onSwitchChange = onSwitchChange
)
}
@Composablefun FunctionB(switchState: Boolean, onSwitchChange : (Boolean) -> Unit ) {
Switch(
checked = switchState,
onCheckedChange = onSwitchChange
)
}
Code language: Kotlin (kotlin)
The first code block in this section should read as follows:
@Composablefun DemoScreen(modifier: Modifier = Modifier) {
Column {
MyTextField()
FunctionA()
}
}
@Composablefun MyTextField() {
var textState by remember { mutableStateOf("") }
val onTextChange = { text : String ->
textState = text
}
TextField(
value = textState,
onValueChange = onTextChange
)
}
.
.
Code language: Kotlin (kotlin)
The second code block should read as follows:
.
.
@Composablefun DemoScreen(modifier: Modifier = Modifier) {
var textState by remember { mutableStateOf("") }
val onTextChange = { text : String ->
textState = text
}
Column {
MyTextField(text = textState, onTextChange = onTextChange)
FunctionA()
}
}
@Composablefun MyTextField(text: String, onTextChange : (String) -> Unit) {
var textState by remember { mutableStateOf("") }
val onTextChange = { text : String ->
textState = text
}
TextField(
value = text,
onValueChange = onTextChange
)
}
.
.
Code language: Kotlin (kotlin)
If you have encountered an issue with the book not listed above, please contact us, and we will work to resolve the issue for you as quickly as possible.