Created
January 27, 2024 18:46
-
-
Save josphatmwania/ed2a1d9c0efd254ab2c338b88bd60a18 to your computer and use it in GitHub Desktop.
GlassCounter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.josphat.stateapp.screens | |
| import android.widget.Button | |
| import androidx.compose.foundation.layout.Column | |
| import androidx.compose.foundation.layout.padding | |
| import androidx.compose.material3.Text | |
| import androidx.compose.runtime.Composable | |
| import androidx.compose.runtime.MutableState | |
| import androidx.compose.runtime.getValue | |
| import androidx.compose.runtime.mutableStateOf | |
| import androidx.compose.runtime.remember | |
| import androidx.compose.ui.Modifier | |
| import androidx.compose.ui.tooling.preview.Preview | |
| import androidx.compose.ui.unit.dp | |
| import com.josphat.stateapp.ui.theme.StateAppTheme | |
| @Composable | |
| fun GlassCounter(modifier: Modifier = Modifier) { | |
| Column(modifier = modifier.padding(16.dp)) { | |
| var glassCount by remember { mutableStateOf(0)} | |
| Text( | |
| "You have had $glassCount glasses of water today!", | |
| modifier = Modifier.padding(vertical = 28.dp), | |
| ) | |
| Button( onClick = { glassCount++ }, Modifier.padding(top = 18.dp)) { | |
| Text("Add More") | |
| } | |
| // | |
| // Button(onClick = { glassCount.value++ }, Modifier.padding(top = 18.dp)) { | |
| // Text("Minus") | |
| // } | |
| // | |
| } | |
| } | |
| @Preview(showBackground = true) | |
| @Composable | |
| fun DefaultPreview() { | |
| StateAppTheme { | |
| GlassCounter() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment