how to using a injected variable in compose preview

152 Views Asked by At

I have a fragment which has an injected variable timeZoneId, which now I have to pass to a composable.

@Inject
lateinit var timeZoneId: ZoneId

In Composable I have a preview, how can I add this to the preview as a parameter please.

@Composable
fun EditDepTime(
    timeZoneId: ZoneId,
    onCancelEditDepTime: () -> Unit
) {

}

@Preview
@Composable
fun EditDepartureTimePreview() {
    OhmeM3Theme() {
        EditDepartureTime(
            ZoneId, //Need to pass timezoneId here
            {}
        )
    }
}

What do I need to pass to get the preview to work please

Thanks R

1

There are 1 best solutions below

0
Tenfour04 On BEST ANSWER

You need to provide some sample value to the preview because it doesn't have access to runtime values. Here you could put any ZoneId you like, for example:

@Preview
@Composable
fun EditDepartureTimePreview() {
    OhmeM3Theme() {
        EditDepartureTime(
            ZoneId.systemDefault(),
            {}
        )
    }
}