Unverified Commit 37f562fa authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Remove callback asserts on FocusableActionDetector (#58272)

This makes the callback arguments to FocusableActionDetector optional, if you (for instance) only want to define shortcuts and actions and a focus node for something.
parent b0c98b66
...@@ -985,7 +985,6 @@ class _FocusableActionDetectorState extends State<FocusableActionDetector> { ...@@ -985,7 +985,6 @@ class _FocusableActionDetectorState extends State<FocusableActionDetector> {
bool _hovering = false; bool _hovering = false;
void _handleMouseEnter(PointerEnterEvent event) { void _handleMouseEnter(PointerEnterEvent event) {
assert(widget.onShowHoverHighlight != null);
if (!_hovering) { if (!_hovering) {
_mayTriggerCallback(task: () { _mayTriggerCallback(task: () {
_hovering = true; _hovering = true;
...@@ -994,7 +993,6 @@ class _FocusableActionDetectorState extends State<FocusableActionDetector> { ...@@ -994,7 +993,6 @@ class _FocusableActionDetectorState extends State<FocusableActionDetector> {
} }
void _handleMouseExit(PointerExitEvent event) { void _handleMouseExit(PointerExitEvent event) {
assert(widget.onShowHoverHighlight != null);
if (_hovering) { if (_hovering) {
_mayTriggerCallback(task: () { _mayTriggerCallback(task: () {
_hovering = false; _hovering = false;
......
...@@ -600,6 +600,7 @@ void main() { ...@@ -600,6 +600,7 @@ void main() {
WidgetTester tester, { WidgetTester tester, {
bool enabled = true, bool enabled = true,
bool directional = false, bool directional = false,
bool supplyCallbacks = true,
@required Key key, @required Key key,
}) async { }) async {
await tester.pumpWidget( await tester.pumpWidget(
...@@ -620,8 +621,8 @@ void main() { ...@@ -620,8 +621,8 @@ void main() {
actions: <Type, Action<Intent>>{ actions: <Type, Action<Intent>>{
TestIntent: testAction, TestIntent: testAction,
}, },
onShowHoverHighlight: (bool value) => hovering = value, onShowHoverHighlight: supplyCallbacks ? (bool value) => hovering = value : null,
onShowFocusHighlight: (bool value) => focusing = value, onShowFocusHighlight: supplyCallbacks ? (bool value) => focusing = value : null,
child: Container(width: 100, height: 100, key: key), child: Container(width: 100, height: 100, key: key),
), ),
), ),
...@@ -709,6 +710,40 @@ void main() { ...@@ -709,6 +710,40 @@ void main() {
await tester.pump(); await tester.pump();
expect(focusing, isTrue); expect(focusing, isTrue);
}); });
testWidgets('FocusableActionDetector can be used without callbacks', (WidgetTester tester) async {
FocusManager.instance.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
final GlobalKey containerKey = GlobalKey();
await pumpTest(tester, enabled: true, key: containerKey, supplyCallbacks: false);
focusNode.requestFocus();
await tester.pump();
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
addTearDown(gesture.removePointer);
await gesture.moveTo(tester.getCenter(find.byKey(containerKey)));
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
expect(hovering, isFalse);
expect(focusing, isFalse);
expect(invoked, isTrue);
invoked = false;
await pumpTest(tester, enabled: false, key: containerKey, supplyCallbacks: false);
expect(hovering, isFalse);
expect(focusing, isFalse);
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pump();
expect(invoked, isFalse);
await pumpTest(tester, enabled: true, key: containerKey, supplyCallbacks: false);
expect(focusing, isFalse);
expect(hovering, isFalse);
await pumpTest(tester, enabled: false, key: containerKey, supplyCallbacks: false);
expect(focusing, isFalse);
expect(hovering, isFalse);
await gesture.moveTo(Offset.zero);
await pumpTest(tester, enabled: true, key: containerKey, supplyCallbacks: false);
expect(hovering, isFalse);
expect(focusing, isFalse);
});
}); });
group('Diagnostics', () { group('Diagnostics', () {
......
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