hi all, I'm writing to DevForum after few days of struggle 13-15h everyday trying to dig many forum for solution ( try Github for: do to list and many other app built in to switch between toggle and button to see if the issues was coming from here
My App idea seems simple actually very complex to build for me, I have manage to build the solution for one row and it's working but when it goes to adding the row into a list I'm giving up.... I do not understand why in my TimeKeyInRow structure it's working I can clic and get feedback of every single hours but when I add row to a list even if I have already created an ID it's still taking the all row as one isSet
import SwiftUI
struct HourButton: View,Identifiable {
var id: String = "hour"
@State var isSet: Bool
var value: Double = 1
var body: some View {
HStack {
Button {
isSet.toggle()
print("clic already \(isSet) \(id)h & \(value) has Value")
} label: {
Label("8h", systemImage: isSet ? "circle.fill" : "circle")
.labelStyle(.iconOnly)
.foregroundStyle(isSet ? .blue : .gray)
}.id(id)
}
}
}
struct HourButton_Previews: PreviewProvider {
static var previews: some View {
//#Preview {
HourButton(id: "MORN", isSet: true, value: 3)
}
}
This is the Row Part which is working fine
import SwiftUI
struct TimeKeyInRow: View,Identifiable {
var id: String
var project: Project
@Binding var isSet: Bool
let listOfPossibleHours: [Double] = [0.5,1,2,3,4,8]
var body: some View {
HStack {
Text(project.shortname)
Spacer()
HourButton(id: "\(project.shortname)\(0)", isSet: true, value: listOfPossibleHours[0])
HourButton(id: "\(project.shortname)\(1)", isSet: true, value: listOfPossibleHours[1])
HourButton(id: "\(project.shortname)\(2)", isSet: true, value: listOfPossibleHours[2])
HourButton(id: "\(project.shortname)\(3)", isSet: true, value: listOfPossibleHours[3])
HourButton(id: "\(project.shortname)\(4)", isSet: true, value: listOfPossibleHours[4])
Text("\(project.leftPMtime)")
}
}
}
struct TimeKeyInRow_Previews: PreviewProvider {
static var previews: some View {
//#Preview {
let projects = ModelData().projects
TimeKeyInRow(id: "test", project: projects[2], isSet: .constant(true))
}
}
Then the part were the issues is coming
import SwiftUI
struct TimeKeyinList: View, Identifiable{
var id: String
@Environment(ModelData.self) var modelData
let projects = ModelData().projects
@State var isSet: Bool
@State private var hideTeco = false
var filteredProjects: [Project] {
// removeTECO project
modelData.projects.filter { project in
!project.isTeco
}}
var body: some View {
VStack {
HStack {
Text("TIME KEY_IN")
.font(.title)
.multilineTextAlignment(.leading)
.bold()
Spacer()
Text("8h")
.font(.title)
.multilineTextAlignment(.leading)
.bold()
}.padding()
List {
HStack(alignment: .top) {
Text("Project Name")
.frame(width: 80, height: 25)
.font(.caption)
.multilineTextAlignment(.center)
.lineLimit(8)
.allowsTightening(/*@START_MENU_TOKEN@*/true/*@END_MENU_TOKEN@*/)
.multilineTextAlignment(.center)
.bold()
Spacer(minLength:30)
Text("0.5h")
.font(.footnote)
Text("1h")
.font(.footnote)
.padding(/*@START_MENU_TOKEN@*/EdgeInsets()/*@END_MENU_TOKEN@*/)
Text("2h")
.font(.footnote)
.padding(/*@START_MENU_TOKEN@*/EdgeInsets()/*@END_MENU_TOKEN@*/)
Text("3h")
.font(.footnote)
.padding(/*@START_MENU_TOKEN@*/EdgeInsets()/*@END_MENU_TOKEN@*/)
Text("4h")
.font(.footnote)
.padding(/*@START_MENU_TOKEN@*/EdgeInsets()/*@END_MENU_TOKEN@*/)
Text("Time Left")
.frame(width: 60, height: 25)
.font(.caption)
.multilineTextAlignment(.center)
.lineLimit(8)
.allowsTightening(/*@START_MENU_TOKEN@*/true/*@END_MENU_TOKEN@*/)
.multilineTextAlignment(.center)
.bold()
}
ForEach (filteredProjects) { project in
TimeKeyInRow(id: project.shortname, project: project, isSet: $isSet)
}
Divider()
// TimeKeyInRow(project: "TRAINING", isSet: $isSet)
// TimeKeyInRow(isSet: $isSet, projectshortname: "MEETING", timeleft: 0)
// TimeKeyInRow(isSet: $isSet, projectshortname: "NON ALLOCATED", timeleft:0)
// TimeKeyInRow(isSet: $isSet, projectshortname: "HOLIDAY", timeleft:0)
//
// }
// .listStyle(.inset)
// DatePicker(selection: /*@START_MENU_TOKEN@*/.constant(Date())/*@END_MENU_TOKEN@*/, label: { /*@START_MENU_TOKEN@*/Text("Date")/*@END_MENU_TOKEN@*/ })
}.labelsHidden()
}
}
}
struct TimeKeyinList_Previews: PreviewProvider {
static var previews: some View {
//#Preview {
TimeKeyinList(id: "test", isSet: true).environment(ModelData())
}
}