Skip to content

Commit a9c71d7

Browse files
authored
[Reland]: Fix DropdownButton menu clip (#104251)
1 parent 406d86b commit a9c71d7

File tree

2 files changed

+58
-21
lines changed

2 files changed

+58
-21
lines changed

packages/flutter/lib/src/material/dropdown.dart

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -286,27 +286,33 @@ class _DropdownMenuState<T> extends State<_DropdownMenu<T>> {
286286
namesRoute: true,
287287
explicitChildNodes: true,
288288
label: localizations.popupMenuLabel,
289-
child: Material(
290-
type: MaterialType.transparency,
291-
textStyle: route.style,
292-
child: ScrollConfiguration(
293-
// Dropdown menus should never overscroll or display an overscroll indicator.
294-
// Scrollbars are built-in below.
295-
// Platform must use Theme and ScrollPhysics must be Clamping.
296-
behavior: ScrollConfiguration.of(context).copyWith(
297-
scrollbars: false,
298-
overscroll: false,
299-
physics: const ClampingScrollPhysics(),
300-
platform: Theme.of(context).platform,
301-
),
302-
child: PrimaryScrollController(
303-
controller: widget.route.scrollController!,
304-
child: Scrollbar(
305-
thumbVisibility: true,
306-
child: ListView(
307-
padding: kMaterialListPadding,
308-
shrinkWrap: true,
309-
children: children,
289+
child: ClipRRect(
290+
borderRadius: widget.borderRadius ?? BorderRadius.zero,
291+
clipBehavior: widget.borderRadius != null
292+
? Clip.antiAlias
293+
: Clip.none,
294+
child: Material(
295+
type: MaterialType.transparency,
296+
textStyle: route.style,
297+
child: ScrollConfiguration(
298+
// Dropdown menus should never overscroll or display an overscroll indicator.
299+
// Scrollbars are built-in below.
300+
// Platform must use Theme and ScrollPhysics must be Clamping.
301+
behavior: ScrollConfiguration.of(context).copyWith(
302+
scrollbars: false,
303+
overscroll: false,
304+
physics: const ClampingScrollPhysics(),
305+
platform: Theme.of(context).platform,
306+
),
307+
child: PrimaryScrollController(
308+
controller: widget.route.scrollController!,
309+
child: Scrollbar(
310+
thumbVisibility: true,
311+
child: ListView(
312+
padding: kMaterialListPadding,
313+
shrinkWrap: true,
314+
children: children,
315+
),
310316
),
311317
),
312318
),

packages/flutter/test/material/dropdown_test.dart

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3809,4 +3809,35 @@ void main() {
38093809
expect(tester.getBottomRight(find.text(hintText)).dx, 776.0);
38103810
expect(tester.getBottomRight(find.text(hintText)).dy, 350.0);
38113811
});
3812+
3813+
testWidgets('BorderRadius property clips dropdown menu', (WidgetTester tester) async {
3814+
const double radius = 20.0;
3815+
3816+
await tester.pumpWidget(
3817+
MaterialApp(
3818+
home: Scaffold(
3819+
body: Center(
3820+
child: DropdownButtonFormField<String>(
3821+
borderRadius: BorderRadius.circular(radius),
3822+
value: 'One',
3823+
items: <String>['One', 'Two', 'Three', 'Four']
3824+
.map<DropdownMenuItem<String>>((String value) {
3825+
return DropdownMenuItem<String>(
3826+
value: value,
3827+
child: Text(value),
3828+
);
3829+
}).toList(),
3830+
onChanged: (_) { },
3831+
),
3832+
),
3833+
),
3834+
),
3835+
);
3836+
3837+
await tester.tap(find.text('One'));
3838+
await tester.pumpAndSettle();
3839+
3840+
final RenderClipRRect renderClip = tester.allRenderObjects.whereType<RenderClipRRect>().first;
3841+
expect(renderClip.borderRadius, BorderRadius.circular(radius));
3842+
});
38123843
}

0 commit comments

Comments
 (0)