title: Duplicate GlobalKey detected in widget tree
body: <p>I am running into a <code>globalKey</code> error after I navigate from <code>Screen A</code> to <code>Screen B</code> and click a "Cancel" button to go back to <code>Screen A</code>.</p>
  
  <p>It seems like the issue is that <code>Screen B</code> is either </p>
  
  <ul>
  <li>A) Not being disposed of correctly</li>
  <li>B) Is not doing something that it otherwise could</li>
  </ul>
  
  <p>And I don't actually know:</p>
  
  <ul>
  <li>What bad things are happening if I just remove the use of a <code>globalKey</code>? (as to get a better understanding of the fundamentals)</li>
  <li>How can I correctly resolve this issue?</li>
  </ul>
  
  <p>StatefulWidget documentation states:<a href="https://docs.flutter.io/flutter/widgets/StatefulWidget-class.html" rel="noreferrer">enter link description here</a></p>
  
  <blockquote>
    <p>A StatefulWidget keeps the same State object when moving from one
    location in the tree to another if its creator used a GlobalKey for
    its key. Because a widget with a GlobalKey can be used in at most one
    location in the tree, a widget that uses a GlobalKey has at most one
    associated element. <strong>The framework takes advantage of this property
    when moving a widget with a global key from one location in the tree
    to another by grafting the (unique) subtree associated with that
    widget</strong> from the old location to the new location (instead of
    recreating the subtree at the new location). The State objects
    associated with StatefulWidget are grafted along with the rest of the
    subtree, which means the State object is reused (instead of being
    recreated) in the new location. <strong>However, in order to be eligible for
    grafting, the widget must be inserted into the new location in the
    same animation frame</strong> in which it was removed from the old location.</p>
  </blockquote>
  
  <p>Console Error Output:</p>
  
  <pre><code>══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
  The following assertion was thrown while finalizing the widget tree:
  Duplicate GlobalKey detected in widget tree.
  The following GlobalKey was specified multiple times in the widget tree. This will lead to parts of
  the widget tree being truncated unexpectedly, because the second time a key is seen, the previous
  instance is moved to the new location. The key was:
  - [LabeledGlobalKey&lt;FormFieldState&lt;String&gt;&gt;#3c76d]
  This was determined by noticing that after the widget with the above global key was moved out of its
  previous parent, that previous parent never updated during this frame, meaning that it either did
  not update at all or updated before the widget was moved, in either case implying that it still
  thinks that it should have a child with that global key.
  The specific parent that did not update after having one or more children forcibly removed due to
  GlobalKey reparenting is:
  - Column(direction: vertical, mainAxisAlignment: start, crossAxisAlignment: center, renderObject:
  RenderFlex#7595c relayoutBoundary=up1 NEEDS-PAINT)
  A GlobalKey can only be specified on one widget at a time in the widget tree.
  </code></pre>
  
  <p>So this part of the error output:</p>
  
  <blockquote>
    <p>previous parent never updated during this frame, meaning that it
    either did not update at all or updated before the widget was moved</p>
  </blockquote>
  
  <p>makes me think there was some opportunity for my old Stateful widget to do something (either reposition itself or release something as to be disposed correctly.</p>
  
  <p>This seems to be failing in <code>framework.dart</code> on <code>assert(_children.contains(child))</code>:</p>
  
  <pre><code>  @override
    void forgetChild(Element child) {
      assert(_children.contains(child));
      assert(!_forgottenChildren.contains(child));
      _forgottenChildren.add(child);
    }
  </code></pre>