diff --git a/packages/flutter/lib/src/material/list_tile.dart b/packages/flutter/lib/src/material/list_tile.dart index 99566ea00a..ca6a5c3c55 100644 --- a/packages/flutter/lib/src/material/list_tile.dart +++ b/packages/flutter/lib/src/material/list_tile.dart @@ -451,19 +451,22 @@ class ListTile extends StatelessWidget { return new InkWell( onTap: enabled ? onTap : null, onLongPress: enabled ? onLongPress : null, - child: new ConstrainedBox( - constraints: new BoxConstraints(minHeight: tileHeight), - child: new Padding( - padding: const EdgeInsets.symmetric(horizontal: 16.0), - child: new UnconstrainedBox( - constrainedAxis: Axis.horizontal, - child: new SafeArea( - top: false, - bottom: false, - child: new Row(children: children), + child: new Semantics( + selected: selected, + child: new ConstrainedBox( + constraints: new BoxConstraints(minHeight: tileHeight), + child: new Padding( + padding: const EdgeInsets.symmetric(horizontal: 16.0), + child: new UnconstrainedBox( + constrainedAxis: Axis.horizontal, + child: new SafeArea( + top: false, + bottom: false, + child: new Row(children: children), + ), ), - ), - ) + ) + ), ), ); } diff --git a/packages/flutter/test/material/list_tile_test.dart b/packages/flutter/test/material/list_tile_test.dart index e800fc2983..4ed9fc846c 100644 --- a/packages/flutter/test/material/list_tile_test.dart +++ b/packages/flutter/test/material/list_tile_test.dart @@ -2,9 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:ui' show SemanticsFlags; + import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; +import '../widgets/semantics_tester.dart'; + class TestIcon extends StatefulWidget { const TestIcon({ Key key }) : super(key: key); @@ -322,4 +327,52 @@ void main() { expect(textColor(subtitleKey), theme.disabledColor); }); + testWidgets('ListTile semantics', (WidgetTester tester) async { + final SemanticsTester semantics = new SemanticsTester(tester); + + await tester.pumpWidget( + new Material( + child: new Directionality( + textDirection: TextDirection.ltr, + child: new MediaQuery( + data: const MediaQueryData(), + child: new Column( + children: [ + const ListTile( + title: const Text('one'), + ), + const ListTile( + title: const Text('two'), + selected: true, + ), + const ListTile( + title: const Text('three'), + ), + ], + ), + ), + ) + ), + ); + + expect(semantics, hasSemantics( + new TestSemantics.root( + children: [ + new TestSemantics.rootChild( + label: 'one', + ), + new TestSemantics.rootChild( + label: 'two', + flags: [SemanticsFlags.isSelected], + ), + new TestSemantics.rootChild( + label: 'three', + ), + ] + ), + ignoreTransform: true, ignoreId: true, ignoreRect: true), + ); + + semantics.dispose(); + }); }