From fcddc558b682d11ec46de600a0e619b5fdf20c25 Mon Sep 17 00:00:00 2001 From: Maximilian Fischer Date: Fri, 15 Mar 2024 15:14:26 +0100 Subject: [PATCH 1/2] fix: Let Button pass loosen constraints to it's child. --- lib/src/controls/inputs/buttons/base.dart | 8 ++-- test/button_test.dart | 49 +++++++++++++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 test/button_test.dart diff --git a/lib/src/controls/inputs/buttons/base.dart b/lib/src/controls/inputs/buttons/base.dart index 04cd9cc2f..bb0a98262 100644 --- a/lib/src/controls/inputs/buttons/base.dart +++ b/lib/src/controls/inputs/buttons/base.dart @@ -214,10 +214,10 @@ class _BaseButtonState extends State { ), textAlign: TextAlign.center, // used to align the child without expanding the button - child: Column( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.center, - children: [widget.child], + child: Center( + heightFactor: 1, + widthFactor: 1, + child: widget.child, ), ), ), diff --git a/test/button_test.dart b/test/button_test.dart new file mode 100644 index 000000000..918ae11e0 --- /dev/null +++ b/test/button_test.dart @@ -0,0 +1,49 @@ +import 'package:fluent_ui/fluent_ui.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets( + 'Test constraints', + (WidgetTester tester) async { + await tester.pumpWidget(Directionality( + textDirection: TextDirection.ltr, + child: FluentTheme( + data: FluentThemeData(), + child: Center( + child: ConstrainedBox( + constraints: const BoxConstraints( + minWidth: 10, + maxWidth: 100, + minHeight: 20, + maxHeight: 200, + ), + child: Button( + child: const SizedBox.shrink(), + onPressed: () {}, + ), + ), + ), + ), + )); + + var buttonBox = tester.firstRenderObject(find.byType(Button)); + var innerBox = tester.firstRenderObject(find.byType(SizedBox)); + + expect( + buttonBox.constraints, + const BoxConstraints( + minWidth: 10, + maxWidth: 100, + minHeight: 20, + maxHeight: 200, + )); + expect(buttonBox.size.width, greaterThanOrEqualTo(10)); + expect(buttonBox.size.height, greaterThanOrEqualTo(20)); + + expect(innerBox.constraints.smallest, Size.zero); + expect(innerBox.constraints.maxWidth, lessThanOrEqualTo(100)); + expect(innerBox.constraints.maxHeight, lessThanOrEqualTo(200)); + expect(innerBox.size, Size.zero); + }, + ); +} From ab4dfbc6aa5bfffdc9105351d2add60348b1bbc8 Mon Sep 17 00:00:00 2001 From: Maximilian Fischer Date: Fri, 15 Mar 2024 15:17:29 +0100 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a844c590e..28dec63c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## next +* fix: A child of `Button` has an unbound height constraint. ([#1039](https://github.com/bdlukaa/fluent_ui/issues/1039)) + ## 4.8.6 * fix: Pop the menu flyout before than calling the close callback ([#1009](https://github.com/bdlukaa/fluent_ui/issues/1009))