3
@Composable
fun EditNumberField() {
    TextField(value = "", onValueChange = {}){
        
    }
}

It says Unresolved reference: TextField.

I want a TextField so that the user can enter a value but it is showing an error.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841

2 Answers2

3

Check your dependencies in the build.gradle file. You have to add the library:

implementation "androidx.compose.material3:material3:$material3_version"

Also check your import statements in your class:

import androidx.compose.material3

If you are using M2 and M3 together avoid this kind of import of both packages together:

import androidx.compose.material.*
import androidx.compose.material3.*
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
1

Seems the error was resolved for me when I entered experimental annotation like so:

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SearchBar(modifier: Modifier = Modifier) {
    var text by remember { mutableStateOf(TextFieldValue("")) }
    TextField(
        value = text,
        onValueChange = {
            newText -> text = newText
        }
    )
}
Droid Chris
  • 3,455
  • 28
  • 31