ShortcutManager should dispatch creation in constructor. (#133356)
This commit is contained in:
parent
dfd4147cea
commit
cf91262f75
@ -747,7 +747,11 @@ class ShortcutManager with Diagnosticable, ChangeNotifier {
|
|||||||
ShortcutManager({
|
ShortcutManager({
|
||||||
Map<ShortcutActivator, Intent> shortcuts = const <ShortcutActivator, Intent>{},
|
Map<ShortcutActivator, Intent> shortcuts = const <ShortcutActivator, Intent>{},
|
||||||
this.modal = false,
|
this.modal = false,
|
||||||
}) : _shortcuts = shortcuts;
|
}) : _shortcuts = shortcuts {
|
||||||
|
if (kFlutterMemoryAllocationsEnabled) {
|
||||||
|
maybeDispatchObjectCreation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// True if the [ShortcutManager] should not pass on keys that it doesn't
|
/// True if the [ShortcutManager] should not pass on keys that it doesn't
|
||||||
/// handle to any key-handling widgets that are ancestors to this one.
|
/// handle to any key-handling widgets that are ancestors to this one.
|
||||||
@ -1440,6 +1444,7 @@ class _ShortcutRegistrarState extends State<ShortcutRegistrar> {
|
|||||||
void dispose() {
|
void dispose() {
|
||||||
registry.removeListener(_shortcutsChanged);
|
registry.removeListener(_shortcutsChanged);
|
||||||
registry.dispose();
|
registry.dispose();
|
||||||
|
manager.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -666,6 +666,19 @@ void main() {
|
|||||||
expect(pressedKeys, isEmpty);
|
expect(pressedKeys, isEmpty);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('$ShortcutManager dispatches object creation in constructor', () {
|
||||||
|
int eventCount = 0;
|
||||||
|
void listener(ObjectEvent event) => eventCount++;
|
||||||
|
MemoryAllocations.instance.addListener(listener);
|
||||||
|
|
||||||
|
final ShortcutManager registry = ShortcutManager();
|
||||||
|
|
||||||
|
expect(eventCount, 1);
|
||||||
|
|
||||||
|
registry.dispose();
|
||||||
|
MemoryAllocations.instance.removeListener(listener);
|
||||||
|
});
|
||||||
|
|
||||||
testWidgets("Shortcuts passes to the next Shortcuts widget if it doesn't map the key", (WidgetTester tester) async {
|
testWidgets("Shortcuts passes to the next Shortcuts widget if it doesn't map the key", (WidgetTester tester) async {
|
||||||
final GlobalKey containerKey = GlobalKey();
|
final GlobalKey containerKey = GlobalKey();
|
||||||
final List<LogicalKeyboardKey> pressedKeys = <LogicalKeyboardKey>[];
|
final List<LogicalKeyboardKey> pressedKeys = <LogicalKeyboardKey>[];
|
||||||
@ -1853,20 +1866,17 @@ void main() {
|
|||||||
token.dispose();
|
token.dispose();
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('dispatches object creation in constructor', (WidgetTester tester) async {
|
test('dispatches object creation in constructor', () {
|
||||||
final MemoryAllocations ma = MemoryAllocations.instance;
|
|
||||||
assert(!ma.hasListeners);
|
|
||||||
int eventCount = 0;
|
int eventCount = 0;
|
||||||
void listener(ObjectEvent event) => eventCount++;
|
void listener(ObjectEvent event) => eventCount++;
|
||||||
ma.addListener(listener);
|
MemoryAllocations.instance.addListener(listener);
|
||||||
|
|
||||||
final ShortcutRegistry registry = ShortcutRegistry();
|
final ShortcutRegistry registry = ShortcutRegistry();
|
||||||
|
|
||||||
expect(eventCount, 1);
|
expect(eventCount, 1);
|
||||||
|
|
||||||
registry.dispose();
|
registry.dispose();
|
||||||
ma.removeListener(listener);
|
MemoryAllocations.instance.removeListener(listener);
|
||||||
assert(!ma.hasListeners);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user