Unverified Commit fb633715 authored by Darren Austin's avatar Darren Austin Committed by GitHub

Fix for the ListTile horizontalTitleGap calculation introduced with PR #64222. (#70149)

parent dbcd7868
...@@ -1404,7 +1404,7 @@ class _RenderListTile extends RenderBox { ...@@ -1404,7 +1404,7 @@ class _RenderListTile extends RenderBox {
_textDirection = textDirection, _textDirection = textDirection,
_titleBaselineType = titleBaselineType, _titleBaselineType = titleBaselineType,
_subtitleBaselineType = subtitleBaselineType, _subtitleBaselineType = subtitleBaselineType,
_horizontalTitleGap = horizontalTitleGap + visualDensity.horizontal * 2.0, _horizontalTitleGap = horizontalTitleGap,
_minVerticalPadding = minVerticalPadding, _minVerticalPadding = minVerticalPadding,
_minLeadingWidth = minLeadingWidth; _minLeadingWidth = minLeadingWidth;
...@@ -1519,6 +1519,7 @@ class _RenderListTile extends RenderBox { ...@@ -1519,6 +1519,7 @@ class _RenderListTile extends RenderBox {
double get horizontalTitleGap => _horizontalTitleGap; double get horizontalTitleGap => _horizontalTitleGap;
double _horizontalTitleGap; double _horizontalTitleGap;
double get _effectiveHorizontalTitleGap => _horizontalTitleGap + visualDensity.horizontal * 2.0;
set horizontalTitleGap(double value) { set horizontalTitleGap(double value) {
assert(value != null); assert(value != null);
...@@ -1602,7 +1603,7 @@ class _RenderListTile extends RenderBox { ...@@ -1602,7 +1603,7 @@ class _RenderListTile extends RenderBox {
@override @override
double computeMinIntrinsicWidth(double height) { double computeMinIntrinsicWidth(double height) {
final double leadingWidth = leading != null final double leadingWidth = leading != null
? math.max(leading!.getMinIntrinsicWidth(height), _minLeadingWidth) + _horizontalTitleGap ? math.max(leading!.getMinIntrinsicWidth(height), _minLeadingWidth) + _effectiveHorizontalTitleGap
: 0.0; : 0.0;
return leadingWidth return leadingWidth
+ math.max(_minWidth(title, height), _minWidth(subtitle, height)) + math.max(_minWidth(title, height), _minWidth(subtitle, height))
...@@ -1612,7 +1613,7 @@ class _RenderListTile extends RenderBox { ...@@ -1612,7 +1613,7 @@ class _RenderListTile extends RenderBox {
@override @override
double computeMaxIntrinsicWidth(double height) { double computeMaxIntrinsicWidth(double height) {
final double leadingWidth = leading != null final double leadingWidth = leading != null
? math.max(leading!.getMaxIntrinsicWidth(height), _minLeadingWidth) + _horizontalTitleGap ? math.max(leading!.getMaxIntrinsicWidth(height), _minLeadingWidth) + _effectiveHorizontalTitleGap
: 0.0; : 0.0;
return leadingWidth return leadingWidth
+ math.max(_maxWidth(title, height), _maxWidth(subtitle, height)) + math.max(_maxWidth(title, height), _maxWidth(subtitle, height))
...@@ -1708,10 +1709,10 @@ class _RenderListTile extends RenderBox { ...@@ -1708,10 +1709,10 @@ class _RenderListTile extends RenderBox {
); );
final double titleStart = hasLeading final double titleStart = hasLeading
? math.max(_minLeadingWidth, leadingSize.width) + _horizontalTitleGap ? math.max(_minLeadingWidth, leadingSize.width) + _effectiveHorizontalTitleGap
: 0.0; : 0.0;
final double adjustedTrailingWidth = hasTrailing final double adjustedTrailingWidth = hasTrailing
? math.max(trailingSize.width + _horizontalTitleGap, 32.0) ? math.max(trailingSize.width + _effectiveHorizontalTitleGap, 32.0)
: 0.0; : 0.0;
final BoxConstraints textConstraints = looseConstraints.tighten( final BoxConstraints textConstraints = looseConstraints.tighten(
width: tileWidth - titleStart - adjustedTrailingWidth, width: tileWidth - titleStart - adjustedTrailingWidth,
......
...@@ -1929,6 +1929,54 @@ void main() { ...@@ -1929,6 +1929,54 @@ void main() {
expect(right('title'), 728.0); expect(right('title'), 728.0);
}); });
testWidgets('ListTile horizontalTitleGap with visualDensity', (WidgetTester tester) async {
Widget buildFrame({
double? horizontalTitleGap,
VisualDensity? visualDensity
}) {
return MediaQuery(
data: const MediaQueryData(
padding: EdgeInsets.zero,
textScaleFactor: 1.0,
),
child: Directionality(
textDirection: TextDirection.ltr,
child: Material(
child: Container(
alignment: Alignment.topLeft,
child: ListTile(
visualDensity: visualDensity,
horizontalTitleGap: horizontalTitleGap,
leading: const Text('L'),
title: const Text('title'),
trailing: const Text('T'),
),
),
),
),
);
}
double left(String text) => tester.getTopLeft(find.text(text)).dx;
await tester.pumpWidget(buildFrame(
horizontalTitleGap: 10.0,
visualDensity: const VisualDensity(horizontal: VisualDensity.minimumDensity),
));
expect(tester.getSize(find.byType(ListTile)), const Size(800.0, 56.0));
expect(left('title'), 58.0);
// Pump another frame of the same widget to ensure the underlying render
// object did not cache the original horizontalTitleGap calculation based on the
// visualDensity
await tester.pumpWidget(buildFrame(
horizontalTitleGap: 10.0,
visualDensity: const VisualDensity(horizontal: VisualDensity.minimumDensity),
));
expect(tester.getSize(find.byType(ListTile)), const Size(800.0, 56.0));
expect(left('title'), 58.0);
});
testWidgets('ListTile minVerticalPadding = 80.0', (WidgetTester tester) async { testWidgets('ListTile minVerticalPadding = 80.0', (WidgetTester tester) async {
Widget buildFrame(TextDirection textDirection, { double? themeMinVerticalPadding, double? widgetMinVerticalPadding }) { Widget buildFrame(TextDirection textDirection, { double? themeMinVerticalPadding, double? widgetMinVerticalPadding }) {
return MediaQuery( return MediaQuery(
......
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