Unverified Commit 9f2e7088 authored by xubaolin's avatar xubaolin Committed by GitHub

`DropdownMenu.width` should support updating at runtime (#124847)

Fixes https://github.com/flutter/flutter/issues/120567
parent b04efe4e
...@@ -648,6 +648,11 @@ class _DropdownMenuBody extends MultiChildRenderObjectWidget { ...@@ -648,6 +648,11 @@ class _DropdownMenuBody extends MultiChildRenderObjectWidget {
width: width, width: width,
); );
} }
@override
void updateRenderObject(BuildContext context, _RenderDropdownMenuBody renderObject) {
renderObject.width = width;
}
} }
class _DropdownMenuBodyParentData extends ContainerBoxParentData<RenderBox> { } class _DropdownMenuBodyParentData extends ContainerBoxParentData<RenderBox> { }
...@@ -657,10 +662,18 @@ class _RenderDropdownMenuBody extends RenderBox ...@@ -657,10 +662,18 @@ class _RenderDropdownMenuBody extends RenderBox
RenderBoxContainerDefaultsMixin<RenderBox, _DropdownMenuBodyParentData> { RenderBoxContainerDefaultsMixin<RenderBox, _DropdownMenuBodyParentData> {
_RenderDropdownMenuBody({ _RenderDropdownMenuBody({
this.width, double? width,
}); }) : _width = width;
final double? width; double? get width => _width;
double? _width;
set width(double? value) {
if (_width == value) {
return;
}
_width = value;
markNeedsLayout();
}
@override @override
void setupParentData(RenderBox child) { void setupParentData(RenderBox child) {
......
...@@ -193,6 +193,28 @@ void main() { ...@@ -193,6 +193,28 @@ void main() {
expect(buttonSize.width, customSmallWidth); expect(buttonSize.width, customSmallWidth);
}); });
testWidgets('The width property update test', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/120567
final ThemeData themeData = ThemeData();
final List<DropdownMenuEntry<ShortMenu>> shortMenuItems = <DropdownMenuEntry<ShortMenu>>[];
for (final ShortMenu value in ShortMenu.values) {
final DropdownMenuEntry<ShortMenu> entry = DropdownMenuEntry<ShortMenu>(value: value, label: value.label);
shortMenuItems.add(entry);
}
double customWidth = 250.0;
await tester.pumpWidget(buildTest(themeData, shortMenuItems, width: customWidth));
RenderBox box = tester.firstRenderObject(find.byType(DropdownMenu<ShortMenu>));
expect(box.size.width, customWidth);
// Update width
customWidth = 400.0;
await tester.pumpWidget(buildTest(themeData, shortMenuItems, width: customWidth));
box = tester.firstRenderObject(find.byType(DropdownMenu<ShortMenu>));
expect(box.size.width, customWidth);
});
testWidgets('The menuHeight property can be used to show a shorter scrollable menu list instead of the complete list', testWidgets('The menuHeight property can be used to show a shorter scrollable menu list instead of the complete list',
(WidgetTester tester) async { (WidgetTester tester) async {
final ThemeData themeData = ThemeData(); final ThemeData themeData = ThemeData();
......
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