<p dir="auto">Forms make heavy use of GlobalKeys for getting access to the FormState and FormFieldState in order to save or validate. This is more expensive than it needs to be. All we really want is a way to grab the State object of a widget. GlobalKey comes with extra baggage.</p>
<p dir="auto">See <a href="https://github.com/flutter/flutter/blob/master/examples/flutter_gallery/lib/demo/text_field_demo.dart#L62">this example</a> and <a href="https://github.com/flutter/flutter/pull/6569#issuecomment-256783236" data-hovercard-type="pull_request" data-hovercard-url="/flutter/flutter/pull/6569/hovercard">this comment</a>.</p>
<p dir="auto">Something like this would be sufficient:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="class StateKey&lt;T extends State&lt;StatefulWidget&gt;&gt; extends Key {
  // Called when Element is mounted.
  void _register(Element element) {
    currentElement = element;
  }

  StatefulElement currentElement;
  T get currentState =&gt; currentElement?.state;
}"><pre class="notranslate"><code class="notranslate">class StateKey&lt;T extends State&lt;StatefulWidget&gt;&gt; extends Key {
  // Called when Element is mounted.
  void _register(Element element) {
    currentElement = element;
  }

  StatefulElement currentElement;
  T get currentState =&gt; currentElement?.state;
}
</code></pre></div>
<p dir="auto"><a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/Hixie/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/Hixie">@Hixie</a></p>
<p dir="auto">I have a flutter project. Inside of its <code class="notranslate">android</code> folder I have a lot of android code, including background processing classes and some native UI. I updated this code to use the new <code class="notranslate">androidX </code>packages.</p>
<p dir="auto">Now, some of the plugins stopped working. A example is the <code class="notranslate">permission_handler </code>plugin.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="permissionhandler\PermissionHandlerPlugin.kt: (10, 31): Unresolved reference: ActivityCompat
permissionhandler\PermissionHandlerPlugin.kt: (11, 27): Unresolved reference: content
permissionhandler\PermissionHandlerPlugin.kt: (152, 37): Unresolved reference: ContextCompat
permissionhandler\PermissionHandlerPlugin.kt: (191, 20): Unresolved reference: ActivityCompat
permissionhandler\PermissionHandlerPlugin.kt: (235, 13): Unresolved reference: ActivityCompat`"><pre class="notranslate"><code class="notranslate">permissionhandler\PermissionHandlerPlugin.kt: (10, 31): Unresolved reference: ActivityCompat
permissionhandler\PermissionHandlerPlugin.kt: (11, 27): Unresolved reference: content
permissionhandler\PermissionHandlerPlugin.kt: (152, 37): Unresolved reference: ContextCompat
permissionhandler\PermissionHandlerPlugin.kt: (191, 20): Unresolved reference: ActivityCompat
permissionhandler\PermissionHandlerPlugin.kt: (235, 13): Unresolved reference: ActivityCompat`
</code></pre></div>
<p dir="auto">I believe this is because the native Android part of my app is using the AndroidX packages, since those plugins are still using the old support library. In the current state, it is impossible to me to roll back to the support library.</p>
<p dir="auto">Also, when I add the <code class="notranslate">camera</code> plugin I get the following error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
                                 ^"><pre class="notranslate"><code class="notranslate">error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
                                 ^
</code></pre></div>
<p dir="auto">Is this a intended behavior? Can someone give me a light?</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[√] Flutter (Channel beta, v0.9.4, on Microsoft Windows [versÃ£o 10.0.17134.376], locale pt-BR)
[√] Android toolchain - develop for Android devices (Android SDK 28.0.3)
[√] Android Studio (version 3.2)
[√] IntelliJ IDEA Community Edition (version 2018.2)
[√] Connected devices (1 available)

• No issues found!`"><pre class="notranslate"><code class="notranslate">[√] Flutter (Channel beta, v0.9.4, on Microsoft Windows [versÃ£o 10.0.17134.376], locale pt-BR)
[√] Android toolchain - develop for Android devices (Android SDK 28.0.3)
[√] Android Studio (version 3.2)
[√] IntelliJ IDEA Community Edition (version 2018.2)
[√] Connected devices (1 available)

• No issues found!`
</code></pre></div>