From 20fb6621ebb108e0036db1d47248bc0cb82f738c Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Wed, 13 Dec 2017 18:39:36 -0800 Subject: [PATCH] Apply media padding in ListTile (#13545) Applies media padding (e.g. iOS safe area insets) around the list tile children inside the InkWell. Also adds safe area around gallery section titles for consistency with surrounding list tiles. --- .../flutter_gallery/lib/gallery/home.dart | 6 ++- .../flutter/lib/src/material/list_tile.dart | 6 ++- .../test/material/control_list_tile_test.dart | 9 ++-- .../flutter/test/material/list_tile_test.dart | 45 ++++++++++++------- 4 files changed, 45 insertions(+), 21 deletions(-) diff --git a/examples/flutter_gallery/lib/gallery/home.dart b/examples/flutter_gallery/lib/gallery/home.dart index c46022ad60..d44a9d8f63 100644 --- a/examples/flutter_gallery/lib/gallery/home.dart +++ b/examples/flutter_gallery/lib/gallery/home.dart @@ -144,7 +144,11 @@ class GalleryHomeState extends State with SingleTickerProviderState height: 48.0, padding: const EdgeInsetsDirectional.only(start: 16.0), alignment: AlignmentDirectional.centerStart, - child: new Text(galleryItem.category, style: headerStyle) + child: new SafeArea( + top: false, + bottom: false, + child: new Text(galleryItem.category, style: headerStyle), + ), ), ) ); diff --git a/packages/flutter/lib/src/material/list_tile.dart b/packages/flutter/lib/src/material/list_tile.dart index 3b5b8e9150..99566ea00a 100644 --- a/packages/flutter/lib/src/material/list_tile.dart +++ b/packages/flutter/lib/src/material/list_tile.dart @@ -457,7 +457,11 @@ class ListTile extends StatelessWidget { padding: const EdgeInsets.symmetric(horizontal: 16.0), child: new UnconstrainedBox( constrainedAxis: Axis.horizontal, - child: new Row(children: children), + child: new SafeArea( + top: false, + bottom: false, + child: new Row(children: children), + ), ), ) ), diff --git a/packages/flutter/test/material/control_list_tile_test.dart b/packages/flutter/test/material/control_list_tile_test.dart index dc96374b62..0ac7b73225 100644 --- a/packages/flutter/test/material/control_list_tile_test.dart +++ b/packages/flutter/test/material/control_list_tile_test.dart @@ -11,9 +11,12 @@ import 'package:flutter/rendering.dart'; import '../widgets/semantics_tester.dart'; Widget wrap({ Widget child }) { - return new Directionality( - textDirection: TextDirection.ltr, - child: new Material(child: child), + return new MediaQuery( + data: const MediaQueryData(), + child: new Directionality( + textDirection: TextDirection.ltr, + child: new Material(child: child), + ), ); } diff --git a/packages/flutter/test/material/list_tile_test.dart b/packages/flutter/test/material/list_tile_test.dart index ebf467a25d..e800fc2983 100644 --- a/packages/flutter/test/material/list_tile_test.dart +++ b/packages/flutter/test/material/list_tile_test.dart @@ -49,11 +49,16 @@ void main() { final Key trailingKey = new GlobalKey(); bool hasSubtitle; + const double leftPadding = 10.0; + const double rightPadding = 20.0; Widget buildFrame({ bool dense: false, bool isTwoLine: false, bool isThreeLine: false, double textScaleFactor: 1.0 }) { hasSubtitle = isTwoLine || isThreeLine; return new MaterialApp( home: new MediaQuery( - data: new MediaQueryData(textScaleFactor: textScaleFactor), + data: new MediaQueryData( + padding: const EdgeInsets.only(left: leftPadding, right: rightPadding), + textScaleFactor: textScaleFactor, + ), child: new Material( child: new Center( child: new ListTile( @@ -89,13 +94,14 @@ void main() { // 16.0 padding to the left and right of the leading and trailing widgets + // plus the media padding. void testHorizontalGeometry() { - expect(leftKey(leadingKey), 16.0); - expect(left('title'), 72.0); + expect(leftKey(leadingKey), 16.0 + leftPadding); + expect(left('title'), 72.0 + leftPadding); if (hasSubtitle) - expect(left('subtitle'), 72.0); + expect(left('subtitle'), 72.0 + leftPadding); expect(left('title'), rightKey(leadingKey) + 32.0); - expect(rightKey(trailingKey), 800.0 - 16.0); + expect(rightKey(trailingKey), 800.0 - 16.0 - rightPadding); expect(widthKey(trailingKey), 24.0); } @@ -169,14 +175,21 @@ void main() { testWidgets('ListTile geometry (RTL)', (WidgetTester tester) async { - await tester.pumpWidget(const Directionality( - textDirection: TextDirection.rtl, - child: const Material( - child: const Center( - child: const ListTile( - leading: const Text('leading'), - title: const Text('title'), - trailing: const Text('trailing'), + const double leftPadding = 10.0; + const double rightPadding = 20.0; + await tester.pumpWidget(const MediaQuery( + data: const MediaQueryData( + padding: const EdgeInsets.only(left: leftPadding, right: rightPadding), + ), + child: const Directionality( + textDirection: TextDirection.rtl, + child: const Material( + child: const Center( + child: const ListTile( + leading: const Text('leading'), + title: const Text('title'), + trailing: const Text('trailing'), + ), ), ), ), @@ -186,10 +199,10 @@ void main() { double right(String text) => tester.getTopRight(find.text(text)).dx; void testHorizontalGeometry() { - expect(right('leading'), 800.0 - 16.0); - expect(right('title'), 800.0 - 72.0); + expect(right('leading'), 800.0 - 16.0 - rightPadding); + expect(right('title'), 800.0 - 72.0 - rightPadding); expect(left('leading') - right('title'), 16.0); - expect(left('trailing'), 16.0); + expect(left('trailing'), 16.0 + leftPadding); } testHorizontalGeometry();