Expose includeSemantics option to RawKeyboardListener (#56549)
* Expose includeSemantics option to RawKeyboardListener * Revert "Expose includeSemantics option to RawKeyboardListener" This reverts commit 684edccfb0bacb358285b34b7a6dafd45a070ca7. * Set includeSemantics to false * Expose includeSemantics for RawKeyboardListener * Add test
This commit is contained in:
@@ -367,15 +367,17 @@ class Focus extends StatefulWidget {
|
||||
/// still be focused explicitly.
|
||||
final bool skipTraversal;
|
||||
|
||||
/// Include semantics information in this [Focus] widget.
|
||||
/// {@template flutter.widgets.Focus.includeSemantics}
|
||||
/// Include semantics information in this widget.
|
||||
///
|
||||
/// If true, this [Focus] widget will include a [Semantics] node that
|
||||
/// If true, this widget will include a [Semantics] node that
|
||||
/// indicates the [Semantics.focusable] and [Semantics.focused] properties.
|
||||
///
|
||||
/// It is not typical to set this to false, as that can affect the semantics
|
||||
/// information available to accessibility systems.
|
||||
///
|
||||
/// Must not be null, defaults to true.
|
||||
/// {@endtemplate}
|
||||
final bool includeSemantics;
|
||||
|
||||
/// {@template flutter.widgets.Focus.canRequestFocus}
|
||||
|
||||
@@ -39,10 +39,12 @@ class RawKeyboardListener extends StatefulWidget {
|
||||
Key key,
|
||||
@required this.focusNode,
|
||||
this.autofocus = false,
|
||||
this.includeSemantics = true,
|
||||
this.onKey,
|
||||
@required this.child,
|
||||
}) : assert(focusNode != null),
|
||||
assert(autofocus != null),
|
||||
assert(includeSemantics != null),
|
||||
assert(child != null),
|
||||
super(key: key);
|
||||
|
||||
@@ -52,6 +54,9 @@ class RawKeyboardListener extends StatefulWidget {
|
||||
/// {@macro flutter.widgets.Focus.autofocus}
|
||||
final bool autofocus;
|
||||
|
||||
/// {@macro flutter.widgets.Focus.includeSemantics}
|
||||
final bool includeSemantics;
|
||||
|
||||
/// Called whenever this widget receives a raw keyboard event.
|
||||
final ValueChanged<RawKeyEvent> onKey;
|
||||
|
||||
@@ -126,6 +131,7 @@ class _RawKeyboardListenerState extends State<RawKeyboardListener> {
|
||||
return Focus(
|
||||
focusNode: widget.focusNode,
|
||||
autofocus: widget.autofocus,
|
||||
includeSemantics: widget.includeSemantics,
|
||||
child: widget.child,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2044,6 +2044,46 @@ void main() {
|
||||
expect(unfocusableNode.hasFocus, isFalse);
|
||||
});
|
||||
});
|
||||
group(RawKeyboardListener, () {
|
||||
testWidgets('Raw keyboard listener introduces a Semantics node by default', (WidgetTester tester) async {
|
||||
final SemanticsTester semantics = SemanticsTester(tester);
|
||||
final FocusNode focusNode = FocusNode();
|
||||
await tester.pumpWidget(
|
||||
RawKeyboardListener(
|
||||
focusNode: focusNode,
|
||||
child: Container(),
|
||||
),
|
||||
);
|
||||
final TestSemantics expectedSemantics = TestSemantics.root(
|
||||
children: <TestSemantics>[
|
||||
TestSemantics.rootChild(
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isFocusable,
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
expect(semantics, hasSemantics(
|
||||
expectedSemantics,
|
||||
ignoreId: true,
|
||||
ignoreRect: true,
|
||||
ignoreTransform: true,
|
||||
));
|
||||
});
|
||||
testWidgets("Raw keyboard listener doesn't introduce a Semantics node when specified", (WidgetTester tester) async {
|
||||
final SemanticsTester semantics = SemanticsTester(tester);
|
||||
final FocusNode focusNode = FocusNode();
|
||||
await tester.pumpWidget(
|
||||
RawKeyboardListener(
|
||||
focusNode: focusNode,
|
||||
includeSemantics: false,
|
||||
child: Container(),
|
||||
),
|
||||
);
|
||||
final TestSemantics expectedSemantics = TestSemantics.root();
|
||||
expect(semantics, hasSemantics(expectedSemantics));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class TestRoute extends PageRouteBuilder<void> {
|
||||
|
||||
Reference in New Issue
Block a user