mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Fix the effective constraints so that they don't exceed max values (#84285)
This fixes VisualDensity.effectiveConstraints to clamp to the max values of the constraint, instead of to double.infinity.
This commit is contained in:
parent
dff703f09f
commit
c4e8c916d0
@ -2322,11 +2322,14 @@ class VisualDensity with Diagnosticable {
|
|||||||
|
|
||||||
/// Return a copy of [constraints] whose minimum width and height have been
|
/// Return a copy of [constraints] whose minimum width and height have been
|
||||||
/// updated with the [baseSizeAdjustment].
|
/// updated with the [baseSizeAdjustment].
|
||||||
|
///
|
||||||
|
/// The resulting minWidth and minHeight values are clamped to not exceed the
|
||||||
|
/// maxWidth and maxHeight values, respectively.
|
||||||
BoxConstraints effectiveConstraints(BoxConstraints constraints){
|
BoxConstraints effectiveConstraints(BoxConstraints constraints){
|
||||||
assert(constraints != null && constraints.debugAssertIsValid());
|
assert(constraints != null && constraints.debugAssertIsValid());
|
||||||
return constraints.copyWith(
|
return constraints.copyWith(
|
||||||
minWidth: (constraints.minWidth + baseSizeAdjustment.dx).clamp(0.0, double.infinity),
|
minWidth: (constraints.minWidth + baseSizeAdjustment.dx).clamp(0.0, constraints.maxWidth),
|
||||||
minHeight: (constraints.minHeight + baseSizeAdjustment.dy).clamp(0.0, double.infinity),
|
minHeight: (constraints.minHeight + baseSizeAdjustment.dy).clamp(0.0, constraints.maxHeight),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,6 +202,49 @@ void main() {
|
|||||||
}
|
}
|
||||||
}, variant: TargetPlatformVariant.all());
|
}, variant: TargetPlatformVariant.all());
|
||||||
|
|
||||||
|
testWidgets('Ensure Visual Density effective constraints are clamped', (WidgetTester tester) async {
|
||||||
|
const BoxConstraints square = BoxConstraints.tightFor(width: 35, height: 35);
|
||||||
|
BoxConstraints expanded = const VisualDensity(horizontal: 4.0, vertical: 4.0).effectiveConstraints(square);
|
||||||
|
expect(expanded.minWidth, equals(35));
|
||||||
|
expect(expanded.minHeight, equals(35));
|
||||||
|
expect(expanded.maxWidth, equals(35));
|
||||||
|
expect(expanded.maxHeight, equals(35));
|
||||||
|
|
||||||
|
BoxConstraints contracted = const VisualDensity(horizontal: -4.0, vertical: -4.0).effectiveConstraints(square);
|
||||||
|
expect(contracted.minWidth, equals(19));
|
||||||
|
expect(contracted.minHeight, equals(19));
|
||||||
|
expect(expanded.maxWidth, equals(35));
|
||||||
|
expect(expanded.maxHeight, equals(35));
|
||||||
|
|
||||||
|
const BoxConstraints small = BoxConstraints.tightFor(width: 4, height: 4);
|
||||||
|
expanded = const VisualDensity(horizontal: 4.0, vertical: 4.0).effectiveConstraints(small);
|
||||||
|
expect(expanded.minWidth, equals(4));
|
||||||
|
expect(expanded.minHeight, equals(4));
|
||||||
|
expect(expanded.maxWidth, equals(4));
|
||||||
|
expect(expanded.maxHeight, equals(4));
|
||||||
|
|
||||||
|
contracted = const VisualDensity(horizontal: -4.0, vertical: -4.0).effectiveConstraints(small);
|
||||||
|
expect(contracted.minWidth, equals(0));
|
||||||
|
expect(contracted.minHeight, equals(0));
|
||||||
|
expect(expanded.maxWidth, equals(4));
|
||||||
|
expect(expanded.maxHeight, equals(4));
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('Ensure Visual Density effective constraints expand and contract', (WidgetTester tester) async {
|
||||||
|
const BoxConstraints square = BoxConstraints();
|
||||||
|
final BoxConstraints expanded = const VisualDensity(horizontal: 4.0, vertical: 4.0).effectiveConstraints(square);
|
||||||
|
expect(expanded.minWidth, equals(16));
|
||||||
|
expect(expanded.minHeight, equals(16));
|
||||||
|
expect(expanded.maxWidth, equals(double.infinity));
|
||||||
|
expect(expanded.maxHeight, equals(double.infinity));
|
||||||
|
|
||||||
|
final BoxConstraints contracted = const VisualDensity(horizontal: -4.0, vertical: -4.0).effectiveConstraints(square);
|
||||||
|
expect(contracted.minWidth, equals(0));
|
||||||
|
expect(contracted.minHeight, equals(0));
|
||||||
|
expect(expanded.maxWidth, equals(double.infinity));
|
||||||
|
expect(expanded.maxHeight, equals(double.infinity));
|
||||||
|
});
|
||||||
|
|
||||||
testWidgets('ThemeData.copyWith correctly creates new ThemeData with all copied arguments', (WidgetTester tester) async {
|
testWidgets('ThemeData.copyWith correctly creates new ThemeData with all copied arguments', (WidgetTester tester) async {
|
||||||
|
|
||||||
final SliderThemeData sliderTheme = SliderThemeData.fromPrimaryColors(
|
final SliderThemeData sliderTheme = SliderThemeData.fromPrimaryColors(
|
||||||
|
Loading…
Reference in New Issue
Block a user