Below is the code that I have currently
struct CheckListCard: View {
@Binding var checkListData : ChecklistModel
@State var statusList: [String] = []
@State var currentStatus : String = ""
@State var currentRemark: String = ""
@Binding var enableButtonBool: Bool
var body: some View {
VStack{
Text("Description").padding()
.onAppear(){
addData()
}
if checkListData.description != nil{
Text(checkListData.description!)
.padding()
}
Text("Status").padding()
if checkListData.status != nil {
Picker("Status", selection: $currentStatus ) {
ForEach(GeneralMethods().uniqueElementsFrom(array: statusList), id: \.self){ status in
Text(status)
}
}.pickerStyle(SegmentedPickerStyle())
.padding()
.disabled(!enableButtonBool)
}
Text("Remarks")
if checkListData.remarks != nil{
TextField("Remarks", text: $currentRemark)
.disabled(!enableButtonBool)
.padding()
.background(Color(.white))
.cornerRadius(8)
.accentColor(.gray)
}else{
TextField("Remarks", text: $currentRemark)
.disabled(!enableButtonBool)
.padding()
.background(Color(.white))
.cornerRadius(8)
}
}
struct CheckListSheet: View {
@State var taskId: Int
@State var pmTaskResponse : PmTaskResponse
@State var checklistResponse: [ChecklistModel] = [ChecklistModel()]
@State var enableButtonBool: Bool = false
var body: some View {
Text("Checklist Items")
.padding()
.font(.title)
ScrollView{
ForEach(checklistResponse, id:\.self){ checklist in
CheckListCard(checkListData: Binding(get: {
return checklist
}, set: { (newValue) in
checklistResponse.append(newValue)
}) , enableButtonBool: $enableButtonBool)
}
if enableButtonBool{
Button("Update"){
updateCheckList()
}.buttonStyle(MainButton())
}
}
.onAppear(){
getChecklists()
}
}