forked from firka/flutter
FocusableActionDetector now exposes descendantsAreFocusable property (#77288)
This commit is contained in:
@@ -1246,6 +1246,7 @@ class FocusableActionDetector extends StatefulWidget {
|
||||
this.enabled = true,
|
||||
this.focusNode,
|
||||
this.autofocus = false,
|
||||
this.descendantsAreFocusable = true,
|
||||
this.shortcuts,
|
||||
this.actions,
|
||||
this.onShowFocusHighlight,
|
||||
@@ -1274,6 +1275,9 @@ class FocusableActionDetector extends StatefulWidget {
|
||||
/// {@macro flutter.widgets.Focus.autofocus}
|
||||
final bool autofocus;
|
||||
|
||||
/// {@macro flutter.widgets.Focus.descendantsAreFocusable}
|
||||
final bool descendantsAreFocusable;
|
||||
|
||||
/// {@macro flutter.widgets.actions.actions}
|
||||
final Map<Type, Action<Intent>>? actions;
|
||||
|
||||
@@ -1459,6 +1463,7 @@ class _FocusableActionDetectorState extends State<FocusableActionDetector> {
|
||||
child: Focus(
|
||||
focusNode: widget.focusNode,
|
||||
autofocus: widget.autofocus,
|
||||
descendantsAreFocusable: widget.descendantsAreFocusable,
|
||||
canRequestFocus: _canRequestFocus,
|
||||
onFocusChange: _handleFocusChange,
|
||||
child: widget.child,
|
||||
|
||||
@@ -919,6 +919,50 @@ void main() {
|
||||
expect(hovering, isFalse);
|
||||
expect(focusing, isFalse);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'FocusableActionDetector can prevent its descendants from being focusable',
|
||||
(WidgetTester tester) async {
|
||||
final FocusNode buttonNode = FocusNode(debugLabel: 'Test');
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: FocusableActionDetector(
|
||||
descendantsAreFocusable: true,
|
||||
child: MaterialButton(
|
||||
focusNode: buttonNode,
|
||||
child: const Text('Test'),
|
||||
onPressed: () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Button is focusable
|
||||
expect(buttonNode.hasFocus, isFalse);
|
||||
buttonNode.requestFocus();
|
||||
await tester.pump();
|
||||
expect(buttonNode.hasFocus, isTrue);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: FocusableActionDetector(
|
||||
descendantsAreFocusable: false,
|
||||
child: MaterialButton(
|
||||
focusNode: buttonNode,
|
||||
child: const Text('Test'),
|
||||
onPressed: () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Button is NOT focusable
|
||||
expect(buttonNode.hasFocus, isFalse);
|
||||
buttonNode.requestFocus();
|
||||
await tester.pump();
|
||||
expect(buttonNode.hasFocus, isFalse);
|
||||
});
|
||||
});
|
||||
|
||||
group('Diagnostics', () {
|
||||
|
||||
Reference in New Issue
Block a user