How can we dynamically change the items of .toolbar modifier in SwiftUI?
I want to achieve something like the below, but it doesn't compile.
@State private var flag = false
var body: some View {
//
// some view code here
//
.toolbar {
if flag {
ToolbarItemGroup(placement: .principal) {
Text("Something full width")
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
} else {
ToolbarItemGroup(placement: .navigationBarTrailing) {
Button("Something else") { ... }
}
}
}
}

