[ad_1]
I am making an attempt to create a button that shows a special pictures/textual content relying on the present state of a activity.
I’ve discovered the next would not work:
Button{
taskViewModel.completeTask(id: activity.id)
} label: {
if activity.taskCompleted {
Picture(systemName: "sq.")
.foregroundStyle(.black)
.padding(10)
.background(Coloration(.white), in: RoundedRectangle(cornerRadius: 10))
} else {
Picture(systemName: "checkmark.sq.")
.foregroundStyle(.black)
.padding(10)
.background(Coloration(.white), in: RoundedRectangle(cornerRadius: 10))
}
}
However this does work:
if activity.taskCompleted {
Button{
taskViewModel.completeTask(id: activity.id)
} label: {
Picture(systemName: "checkmark.sq.")
.foregroundStyle(.black)
.padding(10)
.background(Coloration(.white), in: RoundedRectangle(cornerRadius: 10))
}
} else {
Button{
taskViewModel.completeTask(id: activity.id)
} label: {
Picture(systemName: "sq.")
.foregroundStyle(.black)
.padding(10)
.background(Coloration(.white), in: RoundedRectangle(cornerRadius: 10))
}
}
The code that does not work is way cleaner!. Certainly there’s a higher approach to do that than what I’ve executed right here?
[ad_2]
