2

I have a project on Jetpack Compose where I need to make a Wheel time picker to choose the time. I found a solution that looked acceptable. https://github.com/commandiron/WheelPickerCompose

Then I got a task to save the chosen time to variable or state and when come back to the page (within ViewPager) I need to see the previously chosen time. The problem is that WheelTimePicker returns the time in LocalTime format which is for API 26 but I have API 24. So LocalTime.of, LocalTime.now() doesn't work. I tried to look for some other solutions but they are mainly on xml, not Compose. So right now I don't know how to save the chosen time and set it in WheelTimePicker...

Could you please help me?

   var time = remember { (LocalTime.of(defaultHour, defaultMinute, defaultSecond)) }


               WheelTimePicker(
                   startTime = LocalTime.now(),   // the problem to set time
                   timeFormat = TimeFormat.AM_PM,
                   size = DpSize(200.dp, 100.dp),
                   rowCount = 3,
                   textStyle = MaterialTheme.typography.titleSmall,
                   textColor = colorResource(id = R.color.primaryLightTextColor),
                   selectorProperties = WheelPickerDefaults.selectorProperties(
                       enabled = true,
                       shape = RoundedCornerShape(10.dp),
                       color = Color(0xFFf1faee).copy(alpha = 0.2f),
                       border = BorderStroke(1.dp, colorResource(id = R.color.time_picker_border))
                   ),
                   onSnappedTime = { snappedTime ->
                       time = snappedTime  // the problem to save time
                   }
               )

enter image description here

Alex20280
  • 97
  • 6
  • 3
    Good news, you can use LocalTime on API 24. You need to add desugaring library, details here https://developer.android.com/studio/write/java8-support – Derek K Apr 29 '23 at 15:09

0 Answers0