Trying to pass variable to next view

hi community,
i am simply trying to pass data from one view to another, but somehow it won't work :-( what am I doing wrong?

i want HomeList to pass the variable parentSection to MenuList:

struct HomeList: View {

var menus = menuData
@State var showContent = false

var body: some View {
ScrollView(.vertical, showsIndicators: false) {
VStack {
HStack {
Text("à la carte")
.font(.largeTitle)
.fontWeight(.heavy)
Spacer()
}
.padding(.leading, 40)

        ScrollView(.horizontal, showsIndicators: false) {
           HStack(spacing: 30.0) {
              ForEach(menus) { item in
                Button(action: { self.showContent.toggle() }) {
                    GeometryReader { geometry in
                       MenuSectionView(name: item.name,
                                  image: item.image,
                                  sectionColor: item.sectionColor)
                          .rotation3DEffect(Angle(degrees: Double(geometry.frame(in: .global).minX - 30) / -40), axis: (x: 0, y: 10.0, z: 0))
                        .sheet(isPresented: self.$showContent) { MenuList(parentSection: item.name) }
                    }
                    .frame(width: 246, height: 360)
                 }
              }
           }
           .padding(.leading, 30)
           .padding(.trailing, 30)
           .padding(.top, 30)
           .padding(.bottom, 70)
           Spacer()
        }
     }
     .padding(.top, 60)
  }

}
}

struct MenuList: View {

var parentSection: String

var body: some View {
    NavigationView {
        
        List {
            ForEach(menuData.filter({$0.name == parentSection})) { section in
                //Section(header: Text(section.name)) {
                    ForEach(section.items) { item in
                        MenuItemRow(item: item)
                    }
                //}
            }
        }
        .navigationBarTitle(parentSection)
    }
}

}

You will get responses in #swift-users. This category is more for development of the Swift compiler

For developers to discuss the development and implementation of the Swift compiler, low-level runtime, and SourceKit. This category will accept email sent to: swift+compiler@forums.swift.org

Terms of Service

Privacy Policy

Cookie Policy