diff --git a/CHANGELOG.md b/CHANGELOG.md index e27a50d72..7cdec4b59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ ## next -* feat: Added `DatePicker.fieldFlex` to control the width proportion of each field. -* fix: `Slider` thumb is correct rendered when it's on the edges. +* fix: A child of `Button` has an unbound height constraint. ([#1039](https://github.com/bdlukaa/fluent_ui/issues/1039)) +* feat: Added `DatePicker.fieldFlex` to control the width proportion of each field. ([#1053](https://github.com/bdlukaa/fluent_ui/pull/1053)) +* fix: `Slider` thumb is correct rendered when it's on the edges. ([#1046](https://github.com/bdlukaa/fluent_ui/pull/1046) * feat: Added `TabView.addIconBuilder` ([#1047](https://github.com/bdlukaa/fluent_ui/pull/1047)) ## 4.8.6 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); + }, + ); +}