mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
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.
This commit is contained in:
parent
b0c98b6651
commit
37f562fa36
@ -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> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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() {
|
|||||||
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() {
|
|||||||
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() {
|
|||||||
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', () {
|
||||||
|
Loading…
Reference in New Issue
Block a user