LocalDate in an stable class in jetpack compose

331 Views Asked by At

I want to have a field in a data class that is type of java.time.LocalDate or kotlinx.datetime.LocalDateTime. This class will be consumed in a composable method.

But in metric report this class is unstable because of this field unstability.

How can I have an stable LocalDateTime class?

1

There are 1 best solutions below

4
F.Mysir On

You can create a data class which you promise to the platform that using @Immutable, you will always make a new copy of the data when you pass it.

for example:

@Immutable
data class ImmutableLocalDateTime(
    val ldt: LocalDateTime
)

Then you can use it on your data class and it is stable now for example:

data class StateClass(
    val randomVar: String,
    val dateTime: ImmutableLocalDateTime
    .
    .
    .
)