Unverified Commit 5584fce3 authored by Todd Volkert's avatar Todd Volkert Committed by GitHub

Switch global key registry to be owned by the build owner. (#74701)

This gets away from the extra static map for global key registrations
in favor of the data structures being instance properties of the build
owner. This still allows for semantically-equivalent static access through
the binding (which in turn gives access to the build owner).

This also adds a `BuildOwner.globalKeyCount` getter to get the count
of global keys associated with widgets currently in the tree.
parent e4c84987
......@@ -1500,6 +1500,20 @@ void main() {
TestRenderObjectElement().debugFillProperties(builder);
expect(builder.properties.any((DiagnosticsNode property) => property.name == 'renderObject' && property.value == null), isTrue);
});
testWidgets('BuildOwner.globalKeyCount keeps track of in-use global keys', (WidgetTester tester) async {
final int initialCount = tester.binding.buildOwner!.globalKeyCount;
final GlobalKey key1 = GlobalKey();
final GlobalKey key2 = GlobalKey();
await tester.pumpWidget(Container(key: key1));
expect(tester.binding.buildOwner!.globalKeyCount, initialCount + 1);
await tester.pumpWidget(Container(key: key1, child: Container()));
expect(tester.binding.buildOwner!.globalKeyCount, initialCount + 1);
await tester.pumpWidget(Container(key: key1, child: Container(key: key2)));
expect(tester.binding.buildOwner!.globalKeyCount, initialCount + 2);
await tester.pumpWidget(Container());
expect(tester.binding.buildOwner!.globalKeyCount, initialCount + 0);
});
}
class _FakeFocusManager implements FocusManager {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment