Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: Let Button pass loosen constraints to it's child. #1040

Merged
merged 3 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/src/controls/inputs/buttons/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ class _BaseButtonState extends State<BaseButton> {
),
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,
),
),
),
Expand Down
49 changes: 49 additions & 0 deletions test/button_test.dart
Original file line number Diff line number Diff line change
@@ -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<RenderBox>(find.byType(Button));
var innerBox = tester.firstRenderObject<RenderBox>(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);
},
);
}
Loading