I have a ForEach listing a lot of eventos, having 1 image button for each of them.
When the button is clicked, I will open a modal with the selectedEvento.
The problem is even though I've the line "self.selectedEvento = evento" inside of the button actions, when I click the button for the first time, the selectedEvento is being passed as nil.
However if I click a second button, the process will happen succesfully.
Code:
...
@State var showModal = false
@State var selectedEvento: Evento!
...
ForEach(store.eventos) { evento in
VStack() {
Button(action: {
self.selectedEvento = evento
self.showModal.toggle()
}) {
WebImage(url: evento.thumbnail)
}
}
.sheet(isPresented: $showModal) {
if self.selectedEvento != nil {
//open detailView
} else {
Text("Some Error State goes here")
}
}
}
** Why is this happening ?
Shoudn't the first click also to be passing the selectedEvento ? Why it doesnt happen ?
Thx
1
0
331