mirror of
https://github.com/flutter/flutter
synced 2024-10-13 11:42:54 +00:00
Make Card explicitChildNodes vs container be configurable (#19693)
This commit is contained in:
parent
9c159638bc
commit
730a534fbb
|
@ -67,6 +67,7 @@ class Card extends StatelessWidget {
|
|||
this.shape,
|
||||
this.margin = const EdgeInsets.all(4.0),
|
||||
this.child,
|
||||
this.semanticContainer = false,
|
||||
}) : super(key: key);
|
||||
|
||||
/// The card's background color.
|
||||
|
@ -100,6 +101,19 @@ class Card extends StatelessWidget {
|
|||
/// `EdgeInsets.all(4.0)`.
|
||||
final EdgeInsetsGeometry margin;
|
||||
|
||||
/// Whether this widget represents a single semantic container, or if false
|
||||
/// a collection of individual semantic nodes.
|
||||
///
|
||||
/// Defaults to false.
|
||||
///
|
||||
/// Setting this flag to true will attempt to merge all child semantics into
|
||||
/// this node. Setting this flag to false will force all child semantic nodes
|
||||
/// to be explicit.
|
||||
///
|
||||
/// This flag should be false if the card contains multiple different types
|
||||
/// of content.
|
||||
final bool semanticContainer;
|
||||
|
||||
/// The widget below this widget in the tree.
|
||||
///
|
||||
/// {@macro flutter.widgets.child}
|
||||
|
@ -108,7 +122,8 @@ class Card extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new Semantics(
|
||||
container: true,
|
||||
container: semanticContainer,
|
||||
explicitChildNodes: !semanticContainer,
|
||||
child: new Container(
|
||||
margin: margin ?? const EdgeInsets.all(4.0),
|
||||
child: new Material(
|
||||
|
|
|
@ -18,6 +18,7 @@ void main() {
|
|||
child: new Material(
|
||||
child: new Center(
|
||||
child: new Card(
|
||||
semanticContainer: false,
|
||||
child: new Column(
|
||||
children: <Widget>[
|
||||
const Text('I am text!'),
|
||||
|
@ -37,25 +38,68 @@ void main() {
|
|||
expect(semantics, hasSemantics(
|
||||
new TestSemantics.root(
|
||||
children: <TestSemantics>[
|
||||
new TestSemantics.rootChild(
|
||||
new TestSemantics(
|
||||
id: 1,
|
||||
label: 'I am text!\nMoar text!!1',
|
||||
label: 'I am text!',
|
||||
textDirection: TextDirection.ltr,
|
||||
children: <TestSemantics>[
|
||||
new TestSemantics(
|
||||
id: 2,
|
||||
label: 'Button',
|
||||
textDirection: TextDirection.ltr,
|
||||
actions: <SemanticsAction>[
|
||||
SemanticsAction.tap,
|
||||
],
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isButton,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
],
|
||||
),
|
||||
),
|
||||
new TestSemantics(
|
||||
id: 2,
|
||||
label: 'Moar text!!1',
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
new TestSemantics(
|
||||
id: 3,
|
||||
label: 'Button',
|
||||
textDirection: TextDirection.ltr,
|
||||
actions: <SemanticsAction>[
|
||||
SemanticsAction.tap,
|
||||
],
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isButton,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
ignoreTransform: true,
|
||||
ignoreRect: true,
|
||||
));
|
||||
|
||||
semantics.dispose();
|
||||
});
|
||||
|
||||
testWidgets('Card merges children when it is a semanticContainer', (WidgetTester tester) async {
|
||||
final SemanticsTester semantics = new SemanticsTester(tester);
|
||||
debugResetSemanticsIdCounter();
|
||||
|
||||
await tester.pumpWidget(
|
||||
new Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: new Material(
|
||||
child: new Center(
|
||||
child: new Card(
|
||||
semanticContainer: true,
|
||||
child: new Column(
|
||||
children: const <Widget>[
|
||||
Text('First child'),
|
||||
Text('Second child')
|
||||
],
|
||||
)
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(semantics, hasSemantics(
|
||||
new TestSemantics.root(
|
||||
children: <TestSemantics>[
|
||||
new TestSemantics(
|
||||
id: 1,
|
||||
label: 'First child\nSecond child',
|
||||
textDirection: TextDirection.ltr,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
Loading…
Reference in a new issue