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.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 {
|
||||||
/// `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 {
|
||||||
@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() {
|
||||||
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,25 +38,68 @@ 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: 'Button',
|
label: 'Moar text!!1',
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
actions: <SemanticsAction>[
|
),
|
||||||
SemanticsAction.tap,
|
new TestSemantics(
|
||||||
],
|
id: 3,
|
||||||
flags: <SemanticsFlag>[
|
label: 'Button',
|
||||||
SemanticsFlag.isButton,
|
textDirection: TextDirection.ltr,
|
||||||
SemanticsFlag.hasEnabledState,
|
actions: <SemanticsAction>[
|
||||||
SemanticsFlag.isEnabled,
|
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