From 12ec7dc8790feb437566c8b8e6b6e883a110b4d1 Mon Sep 17 00:00:00 2001 From: Greg Spencer Date: Mon, 12 Apr 2021 23:55:03 +0000 Subject: [PATCH] Remove a dynamic that is no longer necessary (and the TODO for it) (#80294) --- .../lib/src/widgets/focus_manager.dart | 34 +++++-------------- .../test/widgets/focus_scope_test.dart | 4 +-- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/packages/flutter/lib/src/widgets/focus_manager.dart b/packages/flutter/lib/src/widgets/focus_manager.dart index 6879a57f19..db196044d9 100644 --- a/packages/flutter/lib/src/widgets/focus_manager.dart +++ b/packages/flutter/lib/src/widgets/focus_manager.dart @@ -55,8 +55,7 @@ enum KeyEventResult { /// /// Returns a [KeyEventResult] that describes how, and whether, the key event /// was handled. -// TODO(gspencergoog): Convert this from dynamic to KeyEventResult once migration is complete. -typedef FocusOnKeyCallback = dynamic Function(FocusNode node, RawKeyEvent event); +typedef FocusOnKeyCallback = KeyEventResult Function(FocusNode node, RawKeyEvent event); /// An attachment point for a [FocusNode]. /// @@ -1674,33 +1673,18 @@ class FocusManager with DiagnosticableTreeMixin, ChangeNotifier { bool handled = false; for (final FocusNode node in [_primaryFocus!, ..._primaryFocus!.ancestors]) { if (node.onKey != null) { - // TODO(gspencergoog): Convert this from dynamic to KeyEventResult once migration is complete. - final dynamic result = node.onKey!(node, event); - assert( - result is bool || result is KeyEventResult, - 'Value returned from onKey handler must be a non-null bool or KeyEventResult, not ${result.runtimeType}', - ); - if (result is KeyEventResult) { - switch (result) { - case KeyEventResult.handled: - assert(_focusDebug('Node $node handled key event $event.')); - handled = true; - break; - case KeyEventResult.skipRemainingHandlers: - assert(_focusDebug('Node $node stopped key event propagation: $event.')); - handled = false; - break; - case KeyEventResult.ignored: - continue; - } - } else if (result is bool){ - if (result) { + final KeyEventResult result = node.onKey!(node, event); + switch (result) { + case KeyEventResult.handled: assert(_focusDebug('Node $node handled key event $event.')); handled = true; break; - } else { + case KeyEventResult.skipRemainingHandlers: + assert(_focusDebug('Node $node stopped key event propagation: $event.')); + handled = false; + break; + case KeyEventResult.ignored: continue; - } } break; } diff --git a/packages/flutter/test/widgets/focus_scope_test.dart b/packages/flutter/test/widgets/focus_scope_test.dart index 9bfac7a0e7..c9ad95ef9a 100644 --- a/packages/flutter/test/widgets/focus_scope_test.dart +++ b/packages/flutter/test/widgets/focus_scope_test.dart @@ -1596,7 +1596,7 @@ void main() { bool? keyEventHandled; await tester.pumpWidget( Focus( - onKey: (_, __) => true, // This one does nothing. + onKey: (_, __) => KeyEventResult.ignored, // This one does nothing. focusNode: focusNode, child: Container(key: key1), ), @@ -1611,7 +1611,7 @@ void main() { Focus( onKey: (FocusNode node, RawKeyEvent event) { // The updated handler handles the key. keyEventHandled = true; - return true; + return KeyEventResult.handled; }, focusNode: focusNode, child: Container(key: key1),