Merge pull request #1355 from abarth/current_state

Add a currentWidget and currentState accessor to GlobalKeys
This commit is contained in:
Adam Barth 2015-09-25 14:22:39 -07:00
commit af8019bf69

View File

@ -92,6 +92,15 @@ abstract class GlobalKey extends Key {
} }
} }
Element get currentElement => _registry[this];
Widget get currentWidget => currentElement?.widget;
State get currentState {
Element element = currentElement;
if (element is StatefulComponentElement)
return element.state;
return null;
}
static void registerRemoveListener(GlobalKey key, GlobalKeyRemoveListener listener) { static void registerRemoveListener(GlobalKey key, GlobalKeyRemoveListener listener) {
assert(key != null); assert(key != null);
Set<GlobalKeyRemoveListener> listeners = Set<GlobalKeyRemoveListener> listeners =
@ -109,11 +118,6 @@ abstract class GlobalKey extends Key {
assert(removed); assert(removed);
} }
static Element getElement(GlobalKey key) {
assert(key != null);
return _registry[key];
}
// TODO(ianh): call this // TODO(ianh): call this
static void _notifyListeners() { static void _notifyListeners() {
assert(() { assert(() {