Stepper is still buggy?

Anyone experienced this.

My goal is to use AppStorage to save the value in the stepper but the behavior is whaked. Buttons get disabled even when theyre not at both ends of the array

if i use State, it works a bit better but the buttons only get disabled after the 2nd or 3rd try when the index is either 0 or at the end of the array.

@AppStorage("index") private var opacity = 0

let options = [40, 50, 70, 80, 90, 100]
        Stepper {
          Text("\("Opacity") \(options[opacity].description)%")
        } onIncrement: {
          opacity = opacity + 1
          if opacity >= opacity.count {
            opacity = opacity.count - 1
          }
          print("onincrement="+String(opacity))
        } onDecrement: {
          opacity = opacity - 1
          if opacity < 0 {
            opacity = 0
          }
          print("ondecrement="+String(opacity))
        }

The sample code looks simple. I am not sure what else I could be missing?

Answered by Claude31 in 737888022

Thanks for feedback. I did not see in the posted code where the array is integrated in the stepper.

Good continuation (don't forget to close the thread).

I must miss something.

opacity is an Int

So, what is opacity.count ?

Please show a complete code so that we can test.

Accepted Answer

Thanks for feedback. I did not see in the posted code where the array is integrated in the stepper.

Good continuation (don't forget to close the thread).

Stepper is still buggy?
 
 
Q