Hey All,
The knowledge from the community has been incredible in helping me learn and develop. To everyone who has provided feedback so far, sincerely, thank you.
I'm working on an issue that I've spent about half the day trying to solve and can't figure it out. In short, I'd like to present alerts that are conditional to an if
statement. The rub is, that while I can validate that .onTapGesture is working in either state, I'm not getting the second alert to show if the condition falls to the else
statement, despite getting a console print that validates the object was tapped.
I searched through HWS and the forums but didn't find anything on this matter specifically. So I defaulted to Stack and this seemed to be what a lot of archived projects had recommended. I know each view can only have one alert, but since the view presented is conditional I'm assuming that this would hold true in the manner I've done this.... right? Can anyone provide some insight into what is happening?
Thanks!
VStack {
Text("Night Time")
.font(.subheadline)
.frame(alignment: .center)
if Hours().doubleNightHours > 3.0 {
Image(systemName: "checkmark.circle")
.font(.system(size: 25))
.foregroundColor(.green)
.frame(width: 100, alignment: .center)
.onTapGesture {
nightReqMet = true
print("Tapped")
}
} else {
Image(systemName: "x.circle.fill")
.font(.system(size: 25))
.foregroundColor(.red)
.frame(width: 100, alignment: .center)
.onTapGesture {
nightExplanationShowing = true
print("Tapped")
}
}
}
.frame(width: 100, alignment: .center)
.alert(isPresented: $nightExplanationShowing, content: {
Alert(title: Text("14 CFR Part 61.109(a)(2)"), message: Text("Subsection 109 requires that private pilot applicants have a minimum of 3 hours of night training experience including a 100nm cross-country flight, and 10 total takeoffs and landings at an airport."), dismissButton: .default(Text("Dismiss")))
})
.alert(isPresented: $nightReqMet, content: {
Alert(title: Text("You've Met This Requirement!"), message: Text("Congratulations! You've met the requirements for night experience per 14 CFR Part 61.109(a)(2)!"), dismissButton: .default(Text("Dismiss")))
})