Unverified Commit ddd7e4ea authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

improve semantics of chip demo (#20121)

parent 47bdb54e
...@@ -81,29 +81,41 @@ class _ChipsTile extends StatelessWidget { ...@@ -81,29 +81,41 @@ class _ChipsTile extends StatelessWidget {
// Wraps a list of chips into a ListTile for display as a section in the demo. // Wraps a list of chips into a ListTile for display as a section in the demo.
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new ListTile( final List<Widget> cardChildren = <Widget>[
title: new Padding( new Container(
padding: const EdgeInsets.only(top: 16.0, bottom: 4.0), padding: const EdgeInsets.only(top: 16.0, bottom: 4.0),
alignment: Alignment.center,
child: new Text(label, textAlign: TextAlign.start), child: new Text(label, textAlign: TextAlign.start),
), ),
subtitle: children.isEmpty ];
? new Center( if (children.isNotEmpty) {
child: new Padding( cardChildren.add(new Wrap(
padding: const EdgeInsets.all(8.0), children: children.map((Widget chip) {
child: new Text( return new Padding(
'None', padding: const EdgeInsets.all(2.0),
style: Theme.of(context).textTheme.caption.copyWith(fontStyle: FontStyle.italic), child: chip,
), );
), }).toList()));
) } else {
: new Wrap( final TextStyle textStyle = Theme.of(context).textTheme.caption.copyWith(fontStyle: FontStyle.italic);
children: children cardChildren.add(
.map((Widget chip) => new Padding( new Semantics(
padding: const EdgeInsets.all(4.0), container: true,
child: chip, child: new Container(
)) alignment: Alignment.center,
.toList(), constraints: const BoxConstraints(minWidth: 48.0, minHeight: 48.0),
), padding: const EdgeInsets.all(8.0),
child: new Text('None', style: textStyle),
),
));
}
return new Card(
semanticContainer: false,
child: new Column(
mainAxisSize: MainAxisSize.min,
children: cardChildren,
)
); );
} }
} }
...@@ -297,7 +309,7 @@ class _ChipDemoState extends State<ChipDemo> { ...@@ -297,7 +309,7 @@ class _ChipDemoState extends State<ChipDemo> {
_showShapeBorder = !_showShapeBorder; _showShapeBorder = !_showShapeBorder;
}); });
}, },
icon: const Icon(Icons.vignette), icon: const Icon(Icons.vignette, semanticLabel: 'Update border shape'),
) )
], ],
), ),
...@@ -313,7 +325,7 @@ class _ChipDemoState extends State<ChipDemo> { ...@@ -313,7 +325,7 @@ class _ChipDemoState extends State<ChipDemo> {
), ),
floatingActionButton: new FloatingActionButton( floatingActionButton: new FloatingActionButton(
onPressed: () => setState(_reset), onPressed: () => setState(_reset),
child: const Icon(Icons.refresh), child: const Icon(Icons.refresh, semanticLabel: 'Reset chips'),
), ),
); );
} }
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_gallery/demo/material/chip_demo.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Chip demo has semantic labels', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics();
await tester.pumpWidget(new MaterialApp(
theme: new ThemeData(platform: TargetPlatform.iOS),
home: new ChipDemo(),
));
expect(tester.getSemanticsData(find.byIcon(Icons.vignette)), matchesSemanticsData(
isButton: true,
hasEnabledState: true,
isEnabled: true,
hasTapAction: true,
label: 'Update border shape',
));
expect(tester.getSemanticsData(find.byIcon(Icons.refresh)), matchesSemanticsData(
isButton: true,
hasEnabledState: true,
isEnabled: true,
hasTapAction: true,
label: 'Reset chips',
));
handle.dispose();
});
}
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