-
Notifications
You must be signed in to change notification settings - Fork 201
Expand file tree
/
Copy pathApp.kt
More file actions
75 lines (69 loc) · 2.78 KB
/
App.kt
File metadata and controls
75 lines (69 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.jetbrains.basicsample
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import org.jetbrains.compose.ui.tooling.preview.Preview
@Composable
@Preview
fun App() {
MaterialTheme {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Column(
horizontalAlignment = Alignment.Start,
) {
Text(greet(), Modifier.padding(8.dp))
var firstNumber by rememberSaveable { mutableStateOf("") }
var secondNumber by rememberSaveable { mutableStateOf("") }
Row(verticalAlignment = Alignment.CenterVertically) {
TextField(
value = firstNumber,
onValueChange = { firstNumber = it },
modifier = Modifier.width(100.dp),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
)
Text(text = "+", modifier = Modifier.padding(4.dp))
TextField(
value = secondNumber,
onValueChange = { secondNumber = it },
modifier = Modifier.width(100.dp),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
)
val first = firstNumber.toIntOrNull()
val second = secondNumber.toIntOrNull()
Text(
text = if (first != null && second != null) {
"= ${Calculator.sum(first, second)}"
} else {
"= \uD83E\uDD14"
},
modifier = Modifier
.width(100.dp)
.padding(4.dp)
)
}
}
}
}
}
fun greet(): String {
return Greeting().greeting()
}