Unverified Commit 20fb6621 authored by Chris Bracken's avatar Chris Bracken Committed by GitHub

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.
parent 486aa63b
...@@ -144,7 +144,11 @@ class GalleryHomeState extends State<GalleryHome> with SingleTickerProviderState ...@@ -144,7 +144,11 @@ class GalleryHomeState extends State<GalleryHome> with SingleTickerProviderState
height: 48.0, height: 48.0,
padding: const EdgeInsetsDirectional.only(start: 16.0), padding: const EdgeInsetsDirectional.only(start: 16.0),
alignment: AlignmentDirectional.centerStart, alignment: AlignmentDirectional.centerStart,
child: new Text(galleryItem.category, style: headerStyle) child: new SafeArea(
top: false,
bottom: false,
child: new Text(galleryItem.category, style: headerStyle),
),
), ),
) )
); );
......
...@@ -457,8 +457,12 @@ class ListTile extends StatelessWidget { ...@@ -457,8 +457,12 @@ class ListTile extends StatelessWidget {
padding: const EdgeInsets.symmetric(horizontal: 16.0), padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: new UnconstrainedBox( child: new UnconstrainedBox(
constrainedAxis: Axis.horizontal, constrainedAxis: Axis.horizontal,
child: new SafeArea(
top: false,
bottom: false,
child: new Row(children: children), child: new Row(children: children),
), ),
),
) )
), ),
); );
......
...@@ -11,9 +11,12 @@ import 'package:flutter/rendering.dart'; ...@@ -11,9 +11,12 @@ import 'package:flutter/rendering.dart';
import '../widgets/semantics_tester.dart'; import '../widgets/semantics_tester.dart';
Widget wrap({ Widget child }) { Widget wrap({ Widget child }) {
return new Directionality( return new MediaQuery(
data: const MediaQueryData(),
child: new Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: new Material(child: child), child: new Material(child: child),
),
); );
} }
......
...@@ -49,11 +49,16 @@ void main() { ...@@ -49,11 +49,16 @@ void main() {
final Key trailingKey = new GlobalKey(); final Key trailingKey = new GlobalKey();
bool hasSubtitle; 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 }) { Widget buildFrame({ bool dense: false, bool isTwoLine: false, bool isThreeLine: false, double textScaleFactor: 1.0 }) {
hasSubtitle = isTwoLine || isThreeLine; hasSubtitle = isTwoLine || isThreeLine;
return new MaterialApp( return new MaterialApp(
home: new MediaQuery( 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 Material(
child: new Center( child: new Center(
child: new ListTile( child: new ListTile(
...@@ -89,13 +94,14 @@ void main() { ...@@ -89,13 +94,14 @@ void main() {
// 16.0 padding to the left and right of the leading and trailing widgets // 16.0 padding to the left and right of the leading and trailing widgets
// plus the media padding.
void testHorizontalGeometry() { void testHorizontalGeometry() {
expect(leftKey(leadingKey), 16.0); expect(leftKey(leadingKey), 16.0 + leftPadding);
expect(left('title'), 72.0); expect(left('title'), 72.0 + leftPadding);
if (hasSubtitle) if (hasSubtitle)
expect(left('subtitle'), 72.0); expect(left('subtitle'), 72.0 + leftPadding);
expect(left('title'), rightKey(leadingKey) + 32.0); 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); expect(widthKey(trailingKey), 24.0);
} }
...@@ -169,7 +175,13 @@ void main() { ...@@ -169,7 +175,13 @@ void main() {
testWidgets('ListTile geometry (RTL)', (WidgetTester tester) async { testWidgets('ListTile geometry (RTL)', (WidgetTester tester) async {
await tester.pumpWidget(const Directionality( 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, textDirection: TextDirection.rtl,
child: const Material( child: const Material(
child: const Center( child: const Center(
...@@ -180,16 +192,17 @@ void main() { ...@@ -180,16 +192,17 @@ void main() {
), ),
), ),
), ),
),
)); ));
double left(String text) => tester.getTopLeft(find.text(text)).dx; double left(String text) => tester.getTopLeft(find.text(text)).dx;
double right(String text) => tester.getTopRight(find.text(text)).dx; double right(String text) => tester.getTopRight(find.text(text)).dx;
void testHorizontalGeometry() { void testHorizontalGeometry() {
expect(right('leading'), 800.0 - 16.0); expect(right('leading'), 800.0 - 16.0 - rightPadding);
expect(right('title'), 800.0 - 72.0); expect(right('title'), 800.0 - 72.0 - rightPadding);
expect(left('leading') - right('title'), 16.0); expect(left('leading') - right('title'), 16.0);
expect(left('trailing'), 16.0); expect(left('trailing'), 16.0 + leftPadding);
} }
testHorizontalGeometry(); testHorizontalGeometry();
......
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