I'm using Jetpack Compose in Kotlin and I found this interesting strange problem while dealing with TextField.
According to the documents, I should only fill up two parameters: value
and onValueChange
. But my compiler continue warning me the same massage: None of the following functions can be called with the arguments supplied
.
Below is the part of my code where my compiler warns me, together with the imports:
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.camera.core.CameraSelector
import androidx.camera.core.Preview
import androidx.camera.lifecycle.ProcessCameraProvider
import androidx.camera.view.PreviewView
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.*
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import androidx.compose.ui.window.Dialog
import androidx.core.content.ContextCompat
if(showDialog){
Dialog(onDismissRequest = {showDialog = false}){
var inputText:String by remember{ mutableStateOf("")}
Column(modifier = Modifier.fillMaxSize().padding(16.dp)){
TextField(
value = inputText,
onValueChange = { it:String -> inputText = it},
label = {Text("Age")},
colors = TextFieldDefaults.colors(),
){}
Button(onClick = {
if (inputText.isNotEmpty()) {
dataList.add(inputText)
showDialog = false
}
}){
Text("Submit")
}
}
}
}
There is a similar question, which was asked in 2021. But that question was about delegated properties. But my editor(Intellij Idea) surely recognized the types of my parameters, while suggested that I was missing some other parameters.
I found later that it forced me to fill up colors
, but then showed a red )
, which I cannot understand.
I cannot add a picture, so I marked the characters that should be red as bold:
None of the following functions can be called with the arguments supplied.
Are there any certain ways of solving similar problems?
if(showDialog){
Dialog(onDismissRequest = {showDialog = false}){
var inputText:String by remember{ mutableStateOf("")}
Column(modifier = Modifier.fillMaxSize().padding(16.dp)){
TextField(
value = inputText,
onValueChange = {inputText = it},
label = {Text("Age")},
colors = TextFieldDefaults.colors()
)
Button(onClick = {
if (inputText.isNotEmpty()) {
dataList.add(inputText)
showDialog = false
}
}){
Text("Submit")
}
}
}
}
fixed your code, the entire issue was the {}
after your TextField, the text field was not sure what argument you were trying to pass that as and that's why it was underlining the entire thing