I am trying to create a button at Index 0 of LazyVGrid and on other indexes I want to show data from the api, but I am encountering this error
Static method ‘buildExpression’ requires that ‘Button’ conform to ‘TableRowContent’
struct DroneListView: View {
@State var pushToAddDrone: Bool = false
@State var pushToDroneDetail: Bool = false
@State private var selectedIndex: Int = 0
private let droneCategory = ["All drones", "Multi-Rotator", "Quad-Copter", "Fixed-Wing"]
@ObservedObject var droneViewModel = DroneViewModel()
private let adaptiveColumns = [
GridItem(.flexible(minimum: 10, maximum: .infinity), spacing: 15),
GridItem(.flexible(minimum: 10, maximum: .infinity), spacing: 0)
]
var body: some View {
GeometryReader { geometry in
VStack(alignment: .leading) {
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(0..<droneCategory.count, id: .self) { i in
DroneListcategoryView(isActive: i == selectedIndex, text: droneCategory[i])
.onTapGesture {
selectedIndex = i
}
}
}
.padding(.horizontal, 10)
}
.frame(height: 40)
ScrollView {
LazyVGrid(columns: adaptiveColumns, spacing: 18) {
ForEach(Array(droneViewModel.drones.enumerated()), id: .element.droneId) { index, droneList in
if index == 0 {
Button(action: { //error is coming here
pushToAddDrone.toggle()
}) {
VStack(alignment: .center, spacing: 0) {
ImageTheme().addDroneBtn
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 46, height: 46)
}
.frame(width: UIScreen.screenWidth / 2 - 20, height: 175)
.background(ColorTheme().bgWhiteColor)
.cornerRadius(20)
.background(content: {
shadow
})
}
} else {
Button(action: {
pushToDroneDetail.toggle()
}) {
VStack(alignment: .center, spacing: 0) {
if let droneImg = droneList.droneImg {
Image(droneImg)
.resizable()
.scaledToFit()
.frame(width: 120, height: 120)
.cornerRadius(60)
}
VStack(alignment: .leading) {
if let droneName = droneList.droneName {
Text(droneName)
.foregroundColor(ColorTheme().textColor)
.font(Font.custom(FontTheme().poppinsSemiBold, size: 18))
}
if let droneCategory = droneList.droneCategory {
Text(droneCategory)
.foregroundColor(ColorTheme().greyColor)
.font(Font.custom(FontTheme().poppinsRegular, size: 12))
}
}
.padding()
}
.frame(height: 175)
.background(ColorTheme().bgWhiteColor)
.cornerRadius(20)
.background(content: {
shadow
})
}
}
}
.padding(.vertical, 10)
}
}
}
.padding(.vertical, geometry.size.height * 110.convertToGeometryHeight())
.edgesIgnoringSafeArea([.bottom, .leading, .trailing])
.padding(.horizontal, 8)
.background(ColorTheme().textFieldBgColor)
.onAppear {
droneViewModel.getDroneListing(locationId: "e64c6cec-c8d5-4f43-8641-856939ba62ae")
}
}
.navigationDestination(isPresented: $pushToAddDrone) {
AddDronesView()
.navigationBarBackButtonHidden()
}
.navigationDestination(isPresented: $pushToDroneDetail) {
DroneDetailsView()
.navigationBarBackButtonHidden()
}
}
}