-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Add new properties to DropdownMenu that allows padding customization for its leadingIcon and trailingIcon #175558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…g icon and trailing icon. Add DropDownMenuTrailingIconButtonStyle class that allows customization on how the trailing IconButton in a DropdownMenu menu should be constructed.
…n how its trailing IconButton is being constructed.
…adding of property trailingIconPadding. If trailingIconPadding is null, the padding will depends on inputDecorationTheme.isCollapsed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces new properties to the DropdownMenu widget to allow for more customization of the leading and trailing icons, specifically their padding and the style of the trailing icon button. This is a valuable addition that addresses a known issue with the minimum height of the DropdownMenu. The changes include a new DropDownMenuTrailingIconButtonStyle class, updates to the DropdownMenu widget, and a new example with tests.
My review focuses on some naming conventions and typos in the new API and documentation to improve clarity and consistency with the rest of the Flutter framework. These are important to address before merging as they affect the public API.
...les/api/test/material/dropdown_menu/dropdown_menu.customize_trailing_icon_button.0_test.dart
Outdated
Show resolved
Hide resolved
…ButtonStyle example.
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces new properties to the DropdownMenu widget to allow for more detailed customization of the leading and trailing icons. Specifically, it adds leadingIconPadding, trailingIconPadding, and trailingIconButtonStyle. The trailingIconButtonStyle uses a new helper class, DropdownMenuTrailingIconButtonStyle, to configure the underlying IconButton for the trailing icon. This change effectively addresses the issue of the DropdownMenu's minimum height being dictated by the default IconButton size. The changes include new API documentation, an example, and a corresponding test.
My review has identified a couple of areas for improvement in the documentation to enhance clarity for developers. I've left specific comments on those.
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request adds leadingIconPadding, trailingIconPadding, and trailingIconButtonStyle properties to the DropdownMenu widget. These changes allow for customization of the padding and style of the leading and trailing icons. A new DropdownMenuTrailingIconButtonStyle class is introduced to configure the trailing icon button. An example and a corresponding test for the new functionality have also been added. My feedback includes suggestions to improve documentation clarity and code style.
QuncCccccc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your contribution! We should add unit tests for any new properties we add in dropdown_menu_test.dart.
| /// This sample demonstrates how the [trailingIconButtonStyle] property allows customization on the construction of trailing icon button. | ||
| /// ** See code in examples/api/lib/material/dropdown_menu/dropdown_menu.customize_trailing_icon_button.0.dart ** | ||
| /// {@end-tool} | ||
| final DropdownMenuTrailingIconButtonStyle? trailingIconButtonStyle; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the new DropdownMenuTrailingIconButtonStyle class is necessary for fixing the issue linked. xxxTheme can be used for widget customization, such as IconButtonTheme, but I don't think it's necessary here as well.
| /// it is an extra layer of padding between leading icon widget and the text input field. | ||
| /// | ||
| /// Defaults to EdgeInsets.all(8.0). | ||
| final EdgeInsetsGeometry? leadingIconPadding; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding new APIs that only change the leading and trailing icon paddings. I think maybe we should add "trailingButton" and "leadingButton" so we can set something like:
final Widget trailingButton = widget.showTrailingIcon
? **widget.trailingButton** ?? Padding(...)
: ...Similar for leading button. I think maybe this can be better for leading and trailing button customization. The existing trailingIcon and leadingIcon look a bit confusing and limit the customizability. We can consider to deprecate them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| @@ -0,0 +1,44 @@ | |||
| // Copyright 2014 The Flutter Authors. All rights reserved. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this example looks relatively simple, so I think maybe it's not necessary.
|
Yeah. It seems to me that #176264 can achieve what this PR wants to do, although in a more complicated style. |
|
Yes, #176264 is a more general approach to fix |
|
@dkwingsmt Yes I accept that #176264 by @bleroux provides a better solution to achieve what this PR intentional to do and I will be closing this PR. Thanks for the help~ |
## Description
This PR adds `DropdownMenu.decorationBuilder`.
The goal is to make `DropdownMenu` more flexible.
Before this PR, several fields are used by `DropdownMenu` to create an
inner `InputDecoration`. This approach has several limitations:
- `InputDecoration` has more fields that the ones that are exposed
- `DropdownMenu` makes some choices that can't be change. Especially, it
creates an IconButton (with hardcoded padding) which is passed to
`InputDecoration.suffixIcon`. This inner `IconButton` introduces some
difficulty related to focus management and UI customization.
The new `DropdownMenu.decorationBuilder` property offers users a way to
take control on the inner `InputDecoration` in a non-breaking way.
In a future PR, this property will help replacing the default
`IconButton`.
Currently users can replace the `IconButton` using this code sample:
<details><summary>DropdownMenu without IconButton</summary>
```dart
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
MyApp({super.key});
final List<DropdownMenuEntry<String>> menuEntries = [
"Red",
"Green",
"Blue",
].map((t) => DropdownMenuEntry<String>(label: t, value: t)).toList();
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: SizedBox(
width: 220,
child: DropdownMenu<String>(
expandedInsets: EdgeInsets.zero,
requestFocusOnTap: true,
dropdownMenuEntries: menuEntries,
decorationBuilder: (context, controller) {
return InputDecoration(
labelText: 'Label text',
helperText: 'Select a color or enter one',
suffixIcon: controller.isOpen
? const Icon(Icons.arrow_drop_up)
: const Icon(Icons.arrow_drop_down),
);
},
),
),
),
),
);
}
}
```
</details>
## Related Issue
Fixes [DropDownMenu secondary trailing
widget](#175847)
Will help for [Make DropdownMenu's trailing icon not focusable by
default](#174096)
## Related discussions
#175847 (comment)
#175558 (comment)
## Tests
- Adds 7 tests.
## Description
This PR adds `DropdownMenu.decorationBuilder`.
The goal is to make `DropdownMenu` more flexible.
Before this PR, several fields are used by `DropdownMenu` to create an
inner `InputDecoration`. This approach has several limitations:
- `InputDecoration` has more fields that the ones that are exposed
- `DropdownMenu` makes some choices that can't be change. Especially, it
creates an IconButton (with hardcoded padding) which is passed to
`InputDecoration.suffixIcon`. This inner `IconButton` introduces some
difficulty related to focus management and UI customization.
The new `DropdownMenu.decorationBuilder` property offers users a way to
take control on the inner `InputDecoration` in a non-breaking way.
In a future PR, this property will help replacing the default
`IconButton`.
Currently users can replace the `IconButton` using this code sample:
<details><summary>DropdownMenu without IconButton</summary>
```dart
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
MyApp({super.key});
final List<DropdownMenuEntry<String>> menuEntries = [
"Red",
"Green",
"Blue",
].map((t) => DropdownMenuEntry<String>(label: t, value: t)).toList();
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: SizedBox(
width: 220,
child: DropdownMenu<String>(
expandedInsets: EdgeInsets.zero,
requestFocusOnTap: true,
dropdownMenuEntries: menuEntries,
decorationBuilder: (context, controller) {
return InputDecoration(
labelText: 'Label text',
helperText: 'Select a color or enter one',
suffixIcon: controller.isOpen
? const Icon(Icons.arrow_drop_up)
: const Icon(Icons.arrow_drop_down),
);
},
),
),
),
),
);
}
}
```
</details>
## Related Issue
Fixes [DropDownMenu secondary trailing
widget](flutter#175847)
Will help for [Make DropdownMenu's trailing icon not focusable by
default](flutter#174096)
## Related discussions
flutter#175847 (comment)
flutter#175558 (comment)
## Tests
- Adds 7 tests.
This PR adds new properties to DropdownMenu class that allows padding customization for its leadingIcon and trailingIcon, as well as customization on how the trailing icon button in a DropdownMenu should be constructed. This changes hope to address the issue where a DropdownMenu's minimum size (specifically the height) is affected by the trailing IconButton within it. In which due to the constraints of the IconButton having a minimum size of 48x48 under M3 design guidelines, the DropdownMenu's height is unable to go lower than this value.
Comparison
Before changes:
Code:
After changes:
Code:
Fixes #135903
Pre-launch Checklist
///).