Material3 rememberDatePickerState() crashing in desktop and iOS platforms. I am using kotlin = "2.2.10" version for my Kotlin Compose Multiplatform (KMP/CMP) project. It runs fine on android but can't run on desktop and iOS.
implementation(compose.material3)
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.7.1")
If I don't add the datetime library or add old library(0.6.0) rememberDatePickerState() works in all platforms. but for latest datetime 0.7.1 version date picker state crashes (desktop/iOS).
In compose UI my code is like below:
@OptIn(ExperimentalMaterial3Api::class)
@Composable
@Preview
fun App() {
MaterialTheme {
val state = rememberDatePickerState()
DatePicker( state = state )
}
}
After adding library we got 2 package of Clock. kotlinx clock is depricated:
import kotlin.time.Clock
vs
import kotlinx.datetime.Clock
I need a solution to use latest datetime library with date time picker. I want to use latest library as it has some major changes. In my UI it is mandatory to use date picker. So, I got stuck. If there is no solution & have to use old datetime library tell me how to convert millis to formatted date time with that old library.
I would like to add some screenshots of error for your references:
JVM Desktop platform error:
iOS Error:
I have found a solution to keep using datetime 0.7.1 and also use rememberDatePickerState().
I have commented material3 default library and used updated material3 library.
//implementation(compose.material3) <- ❌
implementation("org.jetbrains.compose.material3:material3:1.10.0-alpha01") // ✅
In latest material3 library has updated datetime library so it works perfectly in iOS jvm and definitely android.
Tips: Go to maven central and search by package to use latest material3 library if you see this after a long time.