From 2f657536c8839ddf85d67bf6a8bf6ed4b9465dc0 Mon Sep 17 00:00:00 2001 From: Taha Tesser Date: Sat, 7 May 2022 12:39:08 +0300 Subject: [PATCH] Fix `DropdownButton` menu clip (#102970) --- .../flutter/lib/src/material/dropdown.dart | 45 ++++++++++--------- .../flutter/test/material/dropdown_test.dart | 31 +++++++++++++ 2 files changed, 55 insertions(+), 21 deletions(-) diff --git a/packages/flutter/lib/src/material/dropdown.dart b/packages/flutter/lib/src/material/dropdown.dart index f62bd4d9cf80..70da898cfff3 100644 --- a/packages/flutter/lib/src/material/dropdown.dart +++ b/packages/flutter/lib/src/material/dropdown.dart @@ -286,27 +286,30 @@ class _DropdownMenuState extends State<_DropdownMenu> { namesRoute: true, explicitChildNodes: true, label: localizations.popupMenuLabel, - child: Material( - type: MaterialType.transparency, - textStyle: route.style, - child: ScrollConfiguration( - // Dropdown menus should never overscroll or display an overscroll indicator. - // Scrollbars are built-in below. - // Platform must use Theme and ScrollPhysics must be Clamping. - behavior: ScrollConfiguration.of(context).copyWith( - scrollbars: false, - overscroll: false, - physics: const ClampingScrollPhysics(), - platform: Theme.of(context).platform, - ), - child: PrimaryScrollController( - controller: widget.route.scrollController!, - child: Scrollbar( - thumbVisibility: true, - child: ListView( - padding: kMaterialListPadding, - shrinkWrap: true, - children: children, + child: ClipRRect( + borderRadius: widget.borderRadius ?? BorderRadius.zero, + child: Material( + type: MaterialType.transparency, + textStyle: route.style, + child: ScrollConfiguration( + // Dropdown menus should never overscroll or display an overscroll indicator. + // Scrollbars are built-in below. + // Platform must use Theme and ScrollPhysics must be Clamping. + behavior: ScrollConfiguration.of(context).copyWith( + scrollbars: false, + overscroll: false, + physics: const ClampingScrollPhysics(), + platform: Theme.of(context).platform, + ), + child: PrimaryScrollController( + controller: widget.route.scrollController!, + child: Scrollbar( + thumbVisibility: true, + child: ListView( + padding: kMaterialListPadding, + shrinkWrap: true, + children: children, + ), ), ), ), diff --git a/packages/flutter/test/material/dropdown_test.dart b/packages/flutter/test/material/dropdown_test.dart index ba00a7e8989c..12c3f2045ce9 100644 --- a/packages/flutter/test/material/dropdown_test.dart +++ b/packages/flutter/test/material/dropdown_test.dart @@ -3839,4 +3839,35 @@ void main() { expect(tester.getBottomRight(find.text(hintText)).dx, 776.0); expect(tester.getBottomRight(find.text(hintText)).dy, 350.0); }); + + testWidgets('BorderRadius property clips dropdown menu', (WidgetTester tester) async { + const double radius = 20.0; + + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: Center( + child: DropdownButtonFormField( + borderRadius: BorderRadius.circular(radius), + value: 'One', + items: ['One', 'Two', 'Three', 'Four'] + .map>((String value) { + return DropdownMenuItem( + value: value, + child: Text(value), + ); + }).toList(), + onChanged: (_) { }, + ), + ), + ), + ), + ); + + await tester.tap(find.text('One')); + await tester.pumpAndSettle(); + + final RenderClipRRect renderClip = tester.allRenderObjects.whereType().first; + expect(renderClip.borderRadius, BorderRadius.circular(radius)); + }); }