List(am.students) { item in
HStack {
Text(item.name).font(fancyFont)
Spacer()
Button(item.casual ? "All Paid" : "Reverse All Paid") {
// Issue: pressing this button also results in Remove button action being invoked.
item.casual = !item.casual
}.foregroundColor(Color(white: 0.15))
.padding(3)
.overlay(
RoundedRectangle(cornerRadius: 5)
.stroke(Color(white: 0.5), lineWidth: 3)
)
Spacer().frame(width: 40)
Button("Remove") {
Task {
await am.delete(student: item)
}
}.foregroundColor(Color(white: 0.15))
.frame(width: 80)
.padding(3)
.overlay(
RoundedRectangle(cornerRadius: 5)
.stroke(Color(white: 0.5), lineWidth: 3)
)
}
}
When "All Paid" button is pressed, the "Remove" button action also executes. At a guess, the list row executes everything?
Mark
You have to set buttonStyle (does not work with default value), such as:
.buttonStyle(.borderless) // Or some other style
So your code:
List(am.students) { item in
HStack {
Text(item.name).font(fancyFont)
Spacer()
Button(item.casual ? "All Paid" : "Reverse All Paid") {
// Issue: pressing this button also results in Remove button action being invoked.
item.casual = !item.casual
}
.buttonStyle(.borderless) // <<-- ADD THIS Or some other style
.foregroundColor(Color(white: 0.15))
.padding(3)
.overlay(
RoundedRectangle(cornerRadius: 5)
.stroke(Color(white: 0.5), lineWidth: 3)
)
Spacer().frame(width: 40)
Button("Remove") {
Task {
await am.delete(student: item)
}
}
.buttonStyle(.borderless) // <<-- ADD THIS Or some other style
.foregroundColor(Color(white: 0.15))
.frame(width: 80)
.padding(3)
.overlay(
RoundedRectangle(cornerRadius: 5)
.stroke(Color(white: 0.5), lineWidth: 3)
)
}
}