0

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

BRDroid
  • 3,920
  • 8
  • 65
  • 143
  • 1
    How could you possibly pass something to a preview that only exists at runtime? `timeZoneId` will be injected when your app is compiled and run. It's not available to use in a preview. – Tenfour04 Aug 16 '23 at 13:04
  • Hello @Tenfour thank you for responding, yes that is correct, so what needs to passed to the preview just to get it to work please – BRDroid Aug 16 '23 at 13:11

1 Answers1

1

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(),
            {}
        )
    }
}
Tenfour04
  • 83,111
  • 11
  • 94
  • 154