Unverified Commit b5d521f9 authored by Hans Muller's avatar Hans Muller Committed by GitHub

VisualDensity should not reduce ButtonStyleButton horizontal padding (#79680)

parent 9699b3bf
...@@ -312,14 +312,15 @@ class _ButtonStyleState extends State<ButtonStyleButton> with TickerProviderStat ...@@ -312,14 +312,15 @@ class _ButtonStyleState extends State<ButtonStyleButton> with TickerProviderStat
} }
} }
final EdgeInsetsGeometry padding = resolvedPadding!.add( // Per the Material Design team: don't allow the VisualDensity
EdgeInsets.only( // adjustment to reduce the width of the left/right padding. If we
left: densityAdjustment.dx, // did, VisualDensity.compact, the default for desktop/web, would
top: densityAdjustment.dy, // reduce the horizontal padding to zero.
right: densityAdjustment.dx, final double dy = densityAdjustment.dy;
bottom: densityAdjustment.dy, final double dx = math.max(0, densityAdjustment.dx);
), final EdgeInsetsGeometry padding = resolvedPadding!
).clamp(EdgeInsets.zero, EdgeInsetsGeometry.infinity); .add(EdgeInsets.fromLTRB(dx, dy, dx, dy))
.clamp(EdgeInsets.zero, EdgeInsetsGeometry.infinity);
// If an opaque button's background is becoming translucent while its // If an opaque button's background is becoming translucent while its
// elevation is changing, change the elevation first. Material implicitly // elevation is changing, change the elevation first. Material implicitly
......
...@@ -649,7 +649,7 @@ void main() { ...@@ -649,7 +649,7 @@ void main() {
await buildTest(const VisualDensity(horizontal: -3.0, vertical: -3.0)); await buildTest(const VisualDensity(horizontal: -3.0, vertical: -3.0));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
childRect = tester.getRect(find.byKey(childKey)); childRect = tester.getRect(find.byKey(childKey));
expect(box.size, equals(const Size(108, 100))); expect(box.size, equals(const Size(132, 100)));
expect(childRect, equals(const Rect.fromLTRB(350, 250, 450, 350))); expect(childRect, equals(const Rect.fromLTRB(350, 250, 450, 350)));
await buildTest(VisualDensity.standard, useText: true); await buildTest(VisualDensity.standard, useText: true);
...@@ -667,7 +667,7 @@ void main() { ...@@ -667,7 +667,7 @@ void main() {
await buildTest(const VisualDensity(horizontal: -3.0, vertical: -3.0), useText: true); await buildTest(const VisualDensity(horizontal: -3.0, vertical: -3.0), useText: true);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
childRect = tester.getRect(find.byKey(childKey)); childRect = tester.getRect(find.byKey(childKey));
expect(box.size, equals(const Size(76, 36))); expect(box.size, equals(const Size(88, 36)));
expect(childRect, equals(const Rect.fromLTRB(372.0, 293.0, 428.0, 307.0))); expect(childRect, equals(const Rect.fromLTRB(372.0, 293.0, 428.0, 307.0)));
}); });
......
...@@ -956,7 +956,7 @@ void main() { ...@@ -956,7 +956,7 @@ void main() {
await buildTest(const VisualDensity(horizontal: -3.0, vertical: -3.0)); await buildTest(const VisualDensity(horizontal: -3.0, vertical: -3.0));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
childRect = tester.getRect(find.byKey(childKey)); childRect = tester.getRect(find.byKey(childKey));
expect(box.size, equals(const Size(108, 100))); expect(box.size, equals(const Size(132, 100)));
expect(childRect, equals(const Rect.fromLTRB(350, 250, 450, 350))); expect(childRect, equals(const Rect.fromLTRB(350, 250, 450, 350)));
await buildTest(VisualDensity.standard, useText: true); await buildTest(VisualDensity.standard, useText: true);
...@@ -974,7 +974,7 @@ void main() { ...@@ -974,7 +974,7 @@ void main() {
await buildTest(const VisualDensity(horizontal: -3.0, vertical: -3.0), useText: true); await buildTest(const VisualDensity(horizontal: -3.0, vertical: -3.0), useText: true);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
childRect = tester.getRect(find.byKey(childKey)); childRect = tester.getRect(find.byKey(childKey));
expect(box.size, equals(const Size(64, 36))); expect(box.size, equals(const Size(88, 36)));
expect(childRect, equals(const Rect.fromLTRB(372.0, 293.0, 428.0, 307.0))); expect(childRect, equals(const Rect.fromLTRB(372.0, 293.0, 428.0, 307.0)));
}); });
......
...@@ -739,7 +739,7 @@ void main() { ...@@ -739,7 +739,7 @@ void main() {
await buildTest(const VisualDensity(horizontal: -3.0, vertical: -3.0)); await buildTest(const VisualDensity(horizontal: -3.0, vertical: -3.0));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
childRect = tester.getRect(find.byKey(childKey)); childRect = tester.getRect(find.byKey(childKey));
expect(box.size, equals(const Size(100, 100))); expect(box.size, equals(const Size(116, 100)));
expect(childRect, equals(const Rect.fromLTRB(350, 250, 450, 350))); expect(childRect, equals(const Rect.fromLTRB(350, 250, 450, 350)));
await buildTest(VisualDensity.standard, useText: true); await buildTest(VisualDensity.standard, useText: true);
...@@ -757,7 +757,7 @@ void main() { ...@@ -757,7 +757,7 @@ void main() {
await buildTest(const VisualDensity(horizontal: -3.0, vertical: -3.0), useText: true); await buildTest(const VisualDensity(horizontal: -3.0, vertical: -3.0), useText: true);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
childRect = tester.getRect(find.byKey(childKey)); childRect = tester.getRect(find.byKey(childKey));
expect(box.size, equals(const Size(56, 36))); expect(box.size, equals(const Size(72, 36)));
expect(childRect, equals(const Rect.fromLTRB(372.0, 293.0, 428.0, 307.0))); expect(childRect, equals(const Rect.fromLTRB(372.0, 293.0, 428.0, 307.0)));
}); });
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:math' as math;
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
...@@ -322,10 +324,11 @@ void main() { ...@@ -322,10 +324,11 @@ void main() {
expect(tester.getCenter(logo), Offset(400.0, 351.0 - density.vertical * 2.0)); expect(tester.getCenter(logo), Offset(400.0, 351.0 - density.vertical * 2.0));
// Also check that the button alignment is true to expectations // Also check that the button alignment is true to expectations
// Buttons do not decrease their horizontal padding per the VisualDensity.
final Finder button = find.byType(ElevatedButton); final Finder button = find.byType(ElevatedButton);
expect( expect(
tester.renderObject<RenderBox>(button).size, tester.renderObject<RenderBox>(button).size,
Size(116.0 + density.horizontal * 8.0, 48.0 + density.vertical * 4.0), Size(116.0 + math.max(0, density.horizontal) * 8.0, 48.0 + density.vertical * 4.0),
); );
expect(tester.getBottomLeft(button).dy, equals(600.0)); expect(tester.getBottomLeft(button).dy, equals(600.0));
expect(tester.getCenter(button).dx, equals(400.0)); expect(tester.getCenter(button).dx, equals(400.0));
...@@ -344,7 +347,8 @@ void main() { ...@@ -344,7 +347,8 @@ void main() {
expect(tester.getCenter(logo).dy, lessThan(351.0)); expect(tester.getCenter(logo).dy, lessThan(351.0));
expect( expect(
tester.renderObject<RenderBox>(button).size, tester.renderObject<RenderBox>(button).size,
Size(116.0 + density.horizontal * 8.0, 48.0 + density.vertical * 4.0), // Buttons do not decrease their horizontal padding per the VisualDensity.
Size(116.0 + math.max(0, density.horizontal) * 8.0, 48.0 + density.vertical * 4.0),
); );
expect(tester.getBottomLeft(button).dy, lessThan(600.0)); expect(tester.getBottomLeft(button).dy, lessThan(600.0));
expect(tester.getCenter(button).dx, equals(400.0)); expect(tester.getCenter(button).dx, equals(400.0));
...@@ -592,10 +596,11 @@ void main() { ...@@ -592,10 +596,11 @@ void main() {
expect(tester.getCenter(logo), Offset(400.0, 351.0 - density.vertical * 2.0)); expect(tester.getCenter(logo), Offset(400.0, 351.0 - density.vertical * 2.0));
// Also check that the button alignment is true to expectations. // Also check that the button alignment is true to expectations.
// Buttons do not decrease their horizontal padding per the VisualDensity.
final Finder button = find.byType(ElevatedButton); final Finder button = find.byType(ElevatedButton);
expect( expect(
tester.renderObject<RenderBox>(button).size, tester.renderObject<RenderBox>(button).size,
Size(116.0 + density.horizontal * 8.0, 48.0 + density.vertical * 4.0), Size(116.0 + math.max(0, density.horizontal) * 8.0, 48.0 + density.vertical * 4.0),
); );
expect(tester.getBottomLeft(button).dy, equals(600.0)); expect(tester.getBottomLeft(button).dy, equals(600.0));
expect(tester.getCenter(button).dx, equals(400.0)); expect(tester.getCenter(button).dx, equals(400.0));
...@@ -616,7 +621,8 @@ void main() { ...@@ -616,7 +621,8 @@ void main() {
expect(tester.getCenter(logo).dy, lessThan(351.0)); expect(tester.getCenter(logo).dy, lessThan(351.0));
expect( expect(
tester.renderObject<RenderBox>(button).size, tester.renderObject<RenderBox>(button).size,
Size(116.0 + density.horizontal * 8.0, 48.0 + density.vertical * 4.0), // Buttons do not decrease their horizontal padding per the VisualDensity.
Size(116.0 + math.max(0, density.horizontal) * 8.0, 48.0 + density.vertical * 4.0),
); );
expect(tester.getBottomLeft(button).dy, equals(600.0)); expect(tester.getBottomLeft(button).dy, equals(600.0));
expect(tester.getCenter(button).dx, equals(400.0)); expect(tester.getCenter(button).dx, equals(400.0));
...@@ -635,7 +641,8 @@ void main() { ...@@ -635,7 +641,8 @@ void main() {
expect(tester.getCenter(logo), Offset(400.0, 351.0 - density.vertical * 2.0)); expect(tester.getCenter(logo), Offset(400.0, 351.0 - density.vertical * 2.0));
expect( expect(
tester.renderObject<RenderBox>(button).size, tester.renderObject<RenderBox>(button).size,
Size(116.0 + density.horizontal * 8.0, 48.0 + density.vertical * 4.0), // Buttons do not decrease their horizontal padding per the VisualDensity.
Size(116.0 + math.max(0, density.horizontal) * 8.0, 48.0 + density.vertical * 4.0),
); );
expect(tester.getBottomLeft(button).dy, equals(600.0)); expect(tester.getBottomLeft(button).dy, equals(600.0));
expect(tester.getCenter(button).dx, equals(400.0)); expect(tester.getCenter(button).dx, equals(400.0));
......
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