From 500a3324a46f22bfe4a8097dfc346cc92580a9a7 Mon Sep 17 00:00:00 2001 From: Dheeraj Verma Date: Thu, 6 Jan 2022 02:20:18 +0530 Subject: [PATCH] [DropdownButtonFormField] Add borderRadius property (#95944) --- .../flutter/lib/src/material/dropdown.dart | 4 ++ .../flutter/test/material/dropdown_test.dart | 47 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/packages/flutter/lib/src/material/dropdown.dart b/packages/flutter/lib/src/material/dropdown.dart index 985414fb1b..faccd47bb3 100644 --- a/packages/flutter/lib/src/material/dropdown.dart +++ b/packages/flutter/lib/src/material/dropdown.dart @@ -1540,6 +1540,9 @@ class DropdownButtonFormField extends FormField { double? menuMaxHeight, bool? enableFeedback, AlignmentGeometry alignment = AlignmentDirectional.centerStart, + BorderRadius? borderRadius, + // When adding new arguments, consider adding similar arguments to + // DropdownButton. }) : assert(items == null || items.isEmpty || value == null || items.where((DropdownMenuItem item) { return item.value == value; @@ -1615,6 +1618,7 @@ class DropdownButtonFormField extends FormField { menuMaxHeight: menuMaxHeight, enableFeedback: enableFeedback, alignment: alignment, + borderRadius: borderRadius, ), ), ); diff --git a/packages/flutter/test/material/dropdown_test.dart b/packages/flutter/test/material/dropdown_test.dart index b5a0340305..c69312c2c6 100644 --- a/packages/flutter/test/material/dropdown_test.dart +++ b/packages/flutter/test/material/dropdown_test.dart @@ -3678,4 +3678,51 @@ void main() { expect(tester.takeException(), null); }); + + testWidgets('BorderRadius property works properly for DropdownButtonFormField', (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(); + + expect( + find.ancestor( + of: find.text('One').last, + matching: find.byType(CustomPaint), + ).at(2), + paints + ..save() + ..rrect() + ..rrect() + ..rrect() + ..rrect(rrect: const RRect.fromLTRBXY(0.0, 0.0, 800.0, 208.0, radius, radius)), + ); + + final InkWell firstItem = tester.widget(find.widgetWithText(InkWell, 'One')); + final InkWell lastItem = tester.widget(find.widgetWithText(InkWell, 'Four')); + + expect(firstItem.borderRadius, const BorderRadius.vertical(top: Radius.circular(radius))); + expect(lastItem.borderRadius, const BorderRadius.vertical(bottom: Radius.circular(radius))); + }); }