title: Flutter - Update parent state from child
body: <p>I'm not able to update the parent state from a child. The child widget has a callback named 'onDragEnd' which is called once the drag and drop operation on a grid cell is finished. At this time the parent (the grid) should rebuild UI according to the items new sort, but nothing happens. If I set a breakpoint before the 'setState()' the 'elems' property contains the correct items with right sorting. Even if I replace the entire list, UI is not updating. Any suggestions? What am I missing? </p>
  
  <pre><code>class _CustomGridState extends State&lt;CustomGrid&gt; { 
  
      List&lt;Pack&gt; elems;
  
      _CustomGridState(this.elems);
  
      @override
      Widget build(BuildContext context) {
           return GridView.count(
                  crossAxisCount: 3,
                  children: this
                    .elems
                    .map((pack) =&gt; PackFingernail(pack: pack,
  
                         onDragEnd: (Pack source, Pack target) {
  
                              var sourceIndex = this.elems.indexWhere((p) =&gt; p.id == source.id);
                              var targetIndex = this.elems.indexWhere((p) =&gt; p.id == target.id);
  
                              this.elems.removeAt(sourceIndex);
                              this.elems.insert(targetIndex, source);
  
                              setState(() {}); // Not working &lt;-----
                         })
  
                     ).toList()
                 );
     }
   }
  </code></pre>