title: Picker doesn't show and hide the selection after item being selected in swiftUI
body: <p>I'm doing a coredata practise project. The problems are when users changes their mind to edit an old order, the color property doesn't display the current saved color, and when user changes a new color from selection the picker won't hide, also the new color is not updated in color property.
  Please help me out, and thank you very much</p>
  <p><a href="https://i.stack.imgur.com/cGD4f.png" rel="nofollow noreferrer">EditOrderView</a></p>
  <p><a href="https://i.stack.imgur.com/ovYEF.png" rel="nofollow noreferrer">Select a new color</a></p>
  <p><a href="https://i.stack.imgur.com/aWG1r.png" rel="nofollow noreferrer">Picker won't hide</a></p>
  <p><a href="https://i.stack.imgur.com/qLXiz.png" rel="nofollow noreferrer">Back to EditOrderView, no color selection updated</a></p>
  <p><a href="https://i.stack.imgur.com/SSvqC.png" rel="nofollow noreferrer">CoreDataList</a></p>
  <blockquote>
  <p>ContentView</p>
  </blockquote>
  <pre><code>import SwiftUI
  
  struct ContentView: View {
      @Environment(\.managedObjectContext) var moc
      @FetchRequest(sortDescriptors: []) var orderDetails: FetchedResults&lt;OrderDetails&gt;
      @State private var isShowingOrder = false
      
      var body: some View {
          NavigationView {
              List{
                  ForEach(orderDetails) { detail in
                      NavigationLink{
                          DetailView(orderDetail: detail)
                      } label: {
                          VStack(alignment: .leading){
                              HStack{
                                  Text(detail.name ?? &quot;Unknown&quot;)
                              }
                              Text(detail.color ?? &quot;Unknown&quot;)
                          }
                      }
                  }
                  .onDelete(perform: deleteOrders)
              }
              .navigationTitle(&quot;Order List&quot;)
              .navigationBarTitleDisplayMode(.inline)
              .toolbar {
                  ToolbarItem(placement: .navigationBarLeading) {
                      EditButton()
                  }
                  
                  ToolbarItem(placement: .navigationBarTrailing) {
                      Button{
                          isShowingOrder.toggle()
                      } label: {
                          Label(&quot;&quot;, systemImage: &quot;plus&quot;)
                      }
                  }
              }
              .sheet(isPresented: $isShowingOrder) {
                  AddOrderView()
              }
          }
      }
      
      func deleteOrders(at offsets: IndexSet) {
          for offset in offsets {
              let order = orderDetails[offset]
              moc.delete(order)
          }
          
          try? moc.save()
      }
  }
  
  struct ContentView_Previews: PreviewProvider {
      static var previews: some View {
          ContentView()
      }
  }
  </code></pre>
  <blockquote>
  <p>AddOrderView</p>
  </blockquote>
  <pre><code>import SwiftUI
  
  struct AddOrderView: View {
      @Environment(\.managedObjectContext) var moc
      @Environment(\.dismiss) var dismiss
      
      @State private var name = &quot;&quot;
      @State private var amount = 0
      @State private var color = &quot;&quot;
      @State private var comments = &quot;&quot;
      
      let colors = [&quot;red&quot;, &quot;blue&quot;, &quot;green&quot;, &quot;white&quot;, &quot;black&quot;, &quot;orange&quot;]
      
      var body: some View {
          NavigationView{
              Form{
                  Section {
                      TextField(&quot;Name of Product&quot;, text: $name)
                  }
                  
                  Section {
                      Stepper(&quot;Order Amount: \(amount)&quot;, value: $amount, in: 0...100)
                  }
                  
                  Section {
                      Picker(&quot;Color&quot;, selection: $color) {
                          ForEach(colors, id: \.self){
                              Text($0)
                          }
                      }
                  }
                  
                  Section {
                      TextField(&quot;Comments&quot;, text: $comments)
                  } header: {
                      Text(&quot;Please write your special request here:&quot;)
                  }
              }
              .navigationTitle(&quot;Add new order&quot;)
              .navigationBarTitleDisplayMode(.inline)
              .toolbar {
                  ToolbarItem(placement: .navigationBarTrailing) {
                      Button(&quot;Save&quot;) {
                         let newOrder = OrderDetails(context: moc)
                          newOrder.name = name
                          newOrder.amount = Int16(amount)
                          newOrder.color = color
                          newOrder.comments = comments
                          try? moc.save()
                          dismiss()
                      }
                  }
              }
          }
      }
  }
  
  struct AddOrderView_Previews: PreviewProvider {
      static var previews: some View {
          AddOrderView()
      }
  }
  </code></pre>
  <blockquote>
  <p>DetailView</p>
  </blockquote>
  <pre><code>import SwiftUI
  
  struct DetailView: View {
      let orderDetail: OrderDetails
      
      @Environment(\.managedObjectContext) var moc
      @Environment(\.dismiss) var dismiss
      
      @State private var isEditingAgain = false
      
      var body: some View {
          ScrollView{
              VStack{
                  Text(&quot;Order Amount: \(orderDetail.amount)&quot;)
                  Text(&quot;Color: \(orderDetail.color ?? &quot;Unknown&quot;)&quot;)
                  Text(&quot;Comments: \(orderDetail.comments ?? &quot;Unknown&quot;)&quot;)
              }
          }
          .navigationTitle(orderDetail.name ?? &quot;Unknown&quot;)
          .navigationBarTitleDisplayMode(.inline)
          .toolbar {
              
              ToolbarItem(placement: .navigationBarTrailing) {
                  Button {
                      isEditingAgain = true
                  } label: {
                      Label(&quot;&quot;, systemImage: &quot;square.and.pencil&quot;)
                  }
  
              }
          }
          .sheet(isPresented: $isEditingAgain) {
              EditOrderView(currentDetails: orderDetail)
          }
  
      }
  }
  </code></pre>
  <blockquote>
  <p>EditOrderView</p>
  </blockquote>
  <pre><code>import SwiftUI
  
  struct EditOrderView: View {
      @Environment(\.managedObjectContext) var moc
      @Environment(\.dismiss) var dismiss
      
      @ObservedObject var currentDetails: OrderDetails
      
      let editColors = [&quot;red&quot;, &quot;blue&quot;, &quot;green&quot;, &quot;white&quot;, &quot;black&quot;, &quot;orange&quot;]
          
      var body: some View {
          NavigationView{
              Form{
                  Section {
                      TextField(&quot;Name of Product&quot;, text: $currentDetails.name ?? &quot;&quot;)
                  }
                  
                  Section {
                      Stepper(&quot;Order Amount: \(currentDetails.amount)&quot;, value: $currentDetails.amount, in: 0...100)
                  }
                  
                  Section {
                      Picker(&quot;Color&quot;, selection: $currentDetails.color) {
                          ForEach(editColors, id: \.self){
                              Text($0)
                          }
                      }
                  }
                  
                  Section {
                      TextField(&quot;Comments&quot;, text: $currentDetails.comments ?? &quot;&quot;)
                  } header: {
                      Text(&quot;Please write your special request here:&quot;)
                  }
              }
              .navigationTitle(&quot;Edit Order&quot;)
              .navigationBarTitleDisplayMode(.inline)
              .toolbar{
                  ToolbarItem(placement: .navigationBarTrailing){
                      Button(&quot;Save&quot;) {
                          try? self.moc.save()
                          dismiss()
                      }
                  }
              }
          }
      }
  }
  </code></pre>