-1
import SwiftUI

struct SecondView: View {
    var name: String
    var body: some View {
        Text("Main Dishses \(name)")
    }
}

struct ContentView: View {
    @State private var showingSheet = false
    var body: some View {
        Button("Menu") { 
            self.showingSheet.toggle()
        }
        .foregroundColor(.white)
        .font(Font.largeTitle.weight(.bold))
        .lineSpacing(50)
        .frame(width: 300, height: 300, alignment: .bottomLeading)
        .background(
        Image("bg")
            .resizable())
        .cornerRadius(12)
        .position(x: 150, y: 30)
        
        .sheet(isPresented: $showingSheet) {
            SecondView(name: "food")
                .padding()
        }
    }
}

If I try to VStack this, I get errors because I'm adding struct view cmd into the VStack which is the only way to make that code work, I want to add at least 4 of these sheet view buttons, and everything I found online didn't work, please submit a working code of sheet view buttons in a VStack.

aheze
  • 24,434
  • 8
  • 68
  • 125

1 Answers1

0

there you go, 2 buttons in a VStack. You can of course easily make 4 of those.

struct ContentView: View {
    @State private var showingSheet1 = false
    @State private var showingSheet2 = false
    var body: some View {
        VStack (spacing: 77) {
            Button("Menu") {
                showingSheet1.toggle()
            }
            .sheet(isPresented: $showingSheet1) {
                SecondView(name: "lobster")
            }
            Button("Desert") {
                showingSheet2.toggle()
            }
            .sheet(isPresented: $showingSheet2) {
                SecondView(name: "cake")
            }
            
        }
    }
}