Skip to content

Commit e89c29a

Browse files
SalehTZQuncCccccc
andauthored
feat: Add cursorHeight to DropdownMenu (#172615)
This change adds the `cursorHeight` property to `DropdownMenu`, allowing developers to customize the cursor height in the text field within the dropdown. The `cursorHeight` property is passed down to the underlying `TextField` widget. <!-- Thanks for filing a pull request! Reviewers are typically assigned within a week of filing a request. To learn more about code review, see our documentation on Tree Hygiene: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md --> fixes #172425 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Qun Cheng <[email protected]>
1 parent 74d0ca2 commit e89c29a

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ class DropdownMenu<T> extends StatefulWidget {
194194
this.closeBehavior = DropdownMenuCloseBehavior.all,
195195
this.maxLines = 1,
196196
this.textInputAction,
197+
this.cursorHeight,
197198
this.restorationId,
198199
}) : assert(filterCallback == null || enableFilter),
199200
assert(
@@ -558,6 +559,9 @@ class DropdownMenu<T> extends StatefulWidget {
558559
/// {@macro flutter.widgets.TextField.textInputAction}
559560
final TextInputAction? textInputAction;
560561

562+
/// {@macro flutter.widgets.editableText.cursorHeight}
563+
final double? cursorHeight;
564+
561565
/// {@macro flutter.material.textfield.restorationId}
562566
final String? restorationId;
563567

@@ -1112,6 +1116,7 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
11121116
textAlignVertical: TextAlignVertical.center,
11131117
maxLines: widget.maxLines,
11141118
textInputAction: widget.textInputAction,
1119+
cursorHeight: widget.cursorHeight,
11151120
style: effectiveTextStyle,
11161121
controller: _effectiveTextEditingController,
11171122
onEditingComplete: _handleEditingComplete,

packages/flutter/test/material/dropdown_menu_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4515,6 +4515,23 @@ void main() {
45154515
expect(selectedValueText.style.color, disabledColor);
45164516
},
45174517
);
4518+
4519+
testWidgets('DropdownMenu can set cursorHeight', (WidgetTester tester) async {
4520+
const double cursorHeight = 4.0;
4521+
await tester.pumpWidget(
4522+
MaterialApp(
4523+
home: Scaffold(
4524+
body: DropdownMenu<TestMenu>(
4525+
cursorHeight: cursorHeight,
4526+
dropdownMenuEntries: menuChildren,
4527+
),
4528+
),
4529+
),
4530+
);
4531+
4532+
final EditableText editableText = tester.widget(find.byType(EditableText));
4533+
expect(editableText.cursorHeight, cursorHeight);
4534+
});
45184535
}
45194536

45204537
enum TestMenu {

0 commit comments

Comments
 (0)