Add a currentWidget and currentState accessor to GlobalKeys
This commit is contained in:
parent
d717be946a
commit
80997a68d6
@ -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) {
|
||||
assert(key != null);
|
||||
Set<GlobalKeyRemoveListener> listeners =
|
||||
@ -109,11 +118,6 @@ abstract class GlobalKey extends Key {
|
||||
assert(removed);
|
||||
}
|
||||
|
||||
static Element getElement(GlobalKey key) {
|
||||
assert(key != null);
|
||||
return _registry[key];
|
||||
}
|
||||
|
||||
// TODO(ianh): call this
|
||||
static void _notifyListeners() {
|
||||
assert(() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user