I'm trying to get progress value of a progress bar based on another value. Both of these variables (waterQuantity and progress) are in property wrappers @State
This is my code :
struct CircularProgressBar: View {
@State var waterQuantity: Int
@State var progress: Float = (1 + (Float(waterQuantity)/Float(1500))) * 100
var body: some View {
ZStack {
Circle()
.foregroundColor(.white)
.padding(25)
.overlay(
Circle()
.trim(from: 0.0, to: CGFloat(min(self.progress, 1.0)))
.stroke(style: StrokeStyle(lineWidth: 25
, lineCap: .round, lineJoin: .round))
.foregroundColor(Color.blue)
.rotationEffect(Angle(degrees: 270.0))
.animation(.linear)
.padding(50)
)
VStack {
Text(String(format: "%.0i mL", 500))
.font(.largeTitle)
.bold()
.foregroundColor(Color("bgStart"))
Text("1500 mL")
.foregroundColor(.gray)
}
}
}
As you can see, I cannot initialise progress with another variable that has not been initialized yet. I tried passing values with init() and mutating func, but none of these solutions worked for me