OiO.lk English Android Cannot find a parameter with this name: dateValidator in Jetpack Compose DatePicker
Android

Cannot find a parameter with this name: dateValidator in Jetpack Compose DatePicker


I’m trying to use the dateValidator parameter with DatePicker in Jetpack Compose’s Material3 library to restrict users from selecting past dates. However, I’m getting the following error:

Cannot find a parameter with this name: dateValidator
Here’s the code snippet I’m using:
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import java.time.Instant
import java.time.LocalDate
import java.time.ZoneId

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun TaskDatePicker(
    state: DatePickerState,
    isOpen: Boolean,
    confirmButtonText: String = "OK",
    dismissButtonText: String = "Cancel",
    onDismissRequest: () -> Unit,
    onConfirmButtonClicked: () -> Unit
) {
    if (isOpen) {
        DatePickerDialog(
            onDismissRequest = onDismissRequest,
            confirmButton = {
                TextButton(onClick = onConfirmButtonClicked) {
                    Text(text = confirmButtonText)
                }
            },
            dismissButton = {
                TextButton(onClick = onDismissRequest) {
                    Text(text = dismissButtonText)
                }
            },
            content = {
                DatePicker(
                    state = state,
                    dateValidator = { timestamp ->
                        val selectedDate = Instant
                            .ofEpochMilli(timestamp)
                            .atZone(ZoneId.systemDefault())
                            .toLocalDate()
                        val currentDate = LocalDate.now(ZoneId.systemDefault())
                        selectedDate >= currentDate
                    }
                )
            }
        )
    }
}

how fix this issue??

I added the dateValidator parameter in the DatePicker component within DatePickerDialog to restrict past dates from being selected. I expected this to gray out past dates and make them unselectable, as described in some documentation.

What I Expected:

I expected dateValidator to work and disable any dates prior to today’s date within the DatePicker UI.

What Actually Happened:

I received an error: Cannot find a parameter with this name: dateValidator, indicating that this parameter might not be available in my version of the library, or possibly that it’s unsupported in DatePicker.



You need to sign in to view this answers

Exit mobile version