Unverified Commit 730a534f authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Make Card explicitChildNodes vs container be configurable (#19693)

parent 9c159638
...@@ -67,6 +67,7 @@ class Card extends StatelessWidget { ...@@ -67,6 +67,7 @@ class Card extends StatelessWidget {
this.shape, this.shape,
this.margin = const EdgeInsets.all(4.0), this.margin = const EdgeInsets.all(4.0),
this.child, this.child,
this.semanticContainer = false,
}) : super(key: key); }) : super(key: key);
/// The card's background color. /// The card's background color.
...@@ -100,6 +101,19 @@ class Card extends StatelessWidget { ...@@ -100,6 +101,19 @@ class Card extends StatelessWidget {
/// `EdgeInsets.all(4.0)`. /// `EdgeInsets.all(4.0)`.
final EdgeInsetsGeometry margin; 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. /// The widget below this widget in the tree.
/// ///
/// {@macro flutter.widgets.child} /// {@macro flutter.widgets.child}
...@@ -108,7 +122,8 @@ class Card extends StatelessWidget { ...@@ -108,7 +122,8 @@ class Card extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new Semantics( return new Semantics(
container: true, container: semanticContainer,
explicitChildNodes: !semanticContainer,
child: new Container( child: new Container(
margin: margin ?? const EdgeInsets.all(4.0), margin: margin ?? const EdgeInsets.all(4.0),
child: new Material( child: new Material(
......
...@@ -18,6 +18,7 @@ void main() { ...@@ -18,6 +18,7 @@ void main() {
child: new Material( child: new Material(
child: new Center( child: new Center(
child: new Card( child: new Card(
semanticContainer: false,
child: new Column( child: new Column(
children: <Widget>[ children: <Widget>[
const Text('I am text!'), const Text('I am text!'),
...@@ -37,13 +38,18 @@ void main() { ...@@ -37,13 +38,18 @@ void main() {
expect(semantics, hasSemantics( expect(semantics, hasSemantics(
new TestSemantics.root( new TestSemantics.root(
children: <TestSemantics>[ children: <TestSemantics>[
new TestSemantics.rootChild( new TestSemantics(
id: 1, id: 1,
label: 'I am text!\nMoar text!!1', label: 'I am text!',
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
children: <TestSemantics>[ ),
new TestSemantics( new TestSemantics(
id: 2, id: 2,
label: 'Moar text!!1',
textDirection: TextDirection.ltr,
),
new TestSemantics(
id: 3,
label: 'Button', label: 'Button',
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
actions: <SemanticsAction>[ actions: <SemanticsAction>[
...@@ -57,6 +63,44 @@ void main() { ...@@ -57,6 +63,44 @@ void main() {
), ),
], ],
), ),
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,
),
], ],
), ),
ignoreTransform: true, ignoreTransform: true,
......
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