Issue
I'm trying to save a string in cache from TextField but everytime I save a text it just doesn't save the last letter here is my code.
val value = sharedPref.getString("api", "Invalid")
val context = LocalContext.current
var apiState by remember { mutableStateOf("") }
val pushString = sharedPref.edit().putString("api", apiState).apply()
And onclick
I'm executing that pushString
Solution
EDIT
I don't know where the bug was but fixed with the code below
val sharedPref = [email protected](MODE_PRIVATE)
val getString = sharedPref.getString("api", "Invalid")
val apiState = remember { mutableStateOf("") }
TextField(
value = apiState.value,
onValueChange = { apiState.value = it },
)
Button(onClick = { sharedPref.edit().putString("api",apiState.value).apply() }) {
Text(text = "Cache")
}
Answered By - ABINASH KUMAR