Как на странице отобразить данные, введённые пользователям в TextField Jetpack Compose

Рейтинг: 0Ответов: 0Опубликовано: 19.08.2023

Хочу что бы данный введенный пользователям выводился на экран в компонуемый Text из другой функции и в другом activity. Локальная переменная text хранит введенный данный пользователям, как получить доступ к этой переменной из вне функции MoneyTextField?

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MoneyTextField() {
    var text by rememberSaveable { mutableStateOf("") }
    TextField(
        value = text,
        onValueChange = { text = it},
        modifier = Modifier
            .fillMaxWidth()
            .height(62.dp),
        keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Phone),
        singleLine = true,
        textStyle = TextStyle(fontSize = 24.sp, textAlign = TextAlign.End),
        placeholder = { Text(
            "0",
            modifier = Modifier
                .padding(start = 150.dp),
            fontSize = 24.sp) },
        trailingIcon = {
            Text(
                text = "\u20B8",
                modifier = Modifier.padding(end = 156.dp),
                fontSize = 26.sp,
            )
        },
        colors = TextFieldDefaults.textFieldColors(
            containerColor = Color.White,
            cursorColor = Color.Red,
            focusedIndicatorColor = Color.White,
            unfocusedIndicatorColor = Color.White,
        ),
    )
}

Ответы

Ответов пока нет.