Search code examples
androidandroid-jetpack-composemobile-development

Android Jetpack Compose: TextField - None of the functions can be called with the arguments supplied


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.

  • TextField(TextFieldValue, (TextFieldValue) → Unit, Modifier = ..., Boolean = ..., Boolean = ..., TextStyle = ..., (() → Unit)? = ..., (() → Unit)? = ..., (() → Unit)? = ..., (() → Unit)? = ..., (() → Unit)? = ..., (() → Unit)? = ..., (() → Unit)? = ..., Boolean = ..., VisualTransformation = ..., KeyboardOptions = ..., KeyboardActions = ..., Boolean = ..., Int = ..., Int = ..., MutableInteractionSource = ..., Shape = ..., TextFieldColors = ...) defined in androidx. compose. material3
  • TextField(String, (String) → Unit, Modifier = ..., Boolean = ..., Boolean = ..., TextStyle = ..., (() → Unit)? = ..., (() → Unit)? = ..., (() → Unit)? = ..., (() → Unit)? = ..., (() → Unit)? = ..., (() → Unit)? = ..., (() → Unit)? = ..., Boolean = ..., VisualTransformation = ..., KeyboardOptions = ..., KeyboardActions = ..., Boolean = ..., Int = ..., Int = ..., MutableInteractionSource = ..., Shape = ..., TextFieldColors = ...) defined in androidx. compose. material

Are there any certain ways of solving similar problems?


Solution

  • 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