Skip to content

Commit ebb1ea0

Browse files
authored
Merge pull request #440 from AhmedLSayed9/add_mouse_cursor_configuration
Add `mouseCursor` to the dropdown button and MenuItemStyleData to customize the mouse cursor when hovering
2 parents 6791db4 + 11e7120 commit ebb1ea0

5 files changed

Lines changed: 33 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ customize to your needs.
7979
| [underline](https://pub.dev/documentation/dropdown_button2/latest/dropdown_button2/DropdownButton2/underline.html) | The widget to use for drawing the drop-down button's underline | Widget | No |
8080
| [isDense](https://pub.dev/documentation/dropdown_button2/latest/dropdown_button2/DropdownButton2/isDense.html) | Reduce the button's height | bool | No |
8181
| [isExpanded](https://pub.dev/documentation/dropdown_button2/latest/dropdown_button2/DropdownButton2/isExpanded.html) | Makes the button's inner contents expanded (set true to avoid long text overflowing) | bool | No |
82+
| [mouseCursor](https://pub.dev/documentation/dropdown_button2/latest/dropdown_button2/DropdownButton2/mouseCursor.html) | The cursor for a mouse pointer when it enters or is hovering over the button | MouseCursor | No |
8283
| [alignment](https://pub.dev/documentation/dropdown_button2/latest/dropdown_button2/DropdownButton2/alignment.html) | Defines how the hint or the selected item is positioned within the button | AlignmentGeometry | No |
8384
| [buttonStyleData](https://pub.dev/documentation/dropdown_button2/latest/dropdown_button2/DropdownButton2/buttonStyleData.html) | Used to configure the theme of the button | ButtonStyleData | No |
8485
| [iconStyleData](https://pub.dev/documentation/dropdown_button2/latest/dropdown_button2/DropdownButton2/iconStyleData.html) | Used to configure the theme of the button's icon | IconStyleData | No |
@@ -144,6 +145,7 @@ customize to your needs.
144145
| [useDecorationHorizontalPadding](https://pub.dev/documentation/dropdown_button2/latest/dropdown_button2/MenuItemStyleData/useDecorationHorizontalPadding.html) | Determine whether to use the horizontal padding from "decoration.contentPadding" for menu items when using `DropdownButtonFormField2` | bool | No |
145146
| [borderRadius](https://pub.dev/documentation/dropdown_button2/latest/dropdown_button2/MenuItemStyleData/borderRadius.html) | The border radius of the menu item | BorderRadius | No |
146147
| [overlayColor](https://pub.dev/documentation/dropdown_button2/latest/dropdown_button2/MenuItemStyleData/overlayColor.html) | Defines the ink response focus, hover, and splash colors for the items | WidgetStateProperty<Color?> | No |
148+
| [mouseCursor](https://pub.dev/documentation/dropdown_button2/latest/dropdown_button2/MenuItemStyleData/mouseCursor.html) | The cursor for a mouse pointer when it enters or is hovering over a menu item | MouseCursor | No |
147149
| [selectedMenuItemBuilder](https://pub.dev/documentation/dropdown_button2/latest/dropdown_button2/MenuItemStyleData/selectedMenuItemBuilder.html) | A builder to customize the selected menu item | SelectedMenuItemBuilder | No |
148150

149151
#### Subclass DropdownSearchData:

packages/dropdown_button2/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Re-lay out dropdown menu on ancestor scroll.
1010
- Add `barrierBlocksInteraction` to allow interaction with underlying widgets while the dropdown menu is open.
1111
- Properly dispose internal FocusNode when replaced by an external FocusNode.
12+
- Add `mouseCursor` to the dropdown button and MenuItemStyleData to customize the mouse cursor when hovering, closes #416.
1213

1314
## 3.0.0
1415

packages/dropdown_button2/lib/src/dropdown_button2.dart

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class DropdownButton2<T> extends StatefulWidget {
114114
this.focusNode,
115115
this.autofocus = false,
116116
this.enableFeedback,
117+
this.mouseCursor,
117118
this.alignment = AlignmentDirectional.centerStart,
118119
this.buttonStyleData,
119120
this.iconStyleData = const IconStyleData(),
@@ -155,6 +156,7 @@ class DropdownButton2<T> extends StatefulWidget {
155156
required this.focusNode,
156157
required this.autofocus,
157158
required this.enableFeedback,
159+
required this.mouseCursor,
158160
required this.alignment,
159161
required this.buttonStyleData,
160162
required this.iconStyleData,
@@ -310,6 +312,16 @@ class DropdownButton2<T> extends StatefulWidget {
310312
/// * [Feedback] for providing platform-specific feedback to certain actions.
311313
final bool? enableFeedback;
312314

315+
/// The cursor for a mouse pointer when it enters or is hovering over this
316+
/// button.
317+
///
318+
/// {@macro flutter.material.InkWell.mouseCursor}
319+
///
320+
// TODO(Ahmed): Update to [WidgetStateMouseCursor.adaptiveClickable]
321+
// when it's supported by the min version of the package [Flutter>=3.41.0]
322+
/// If this property is null, [WidgetStateMouseCursor.clickable] will be used.
323+
final MouseCursor? mouseCursor;
324+
313325
/// Defines how the hint or the selected item is positioned within the button.
314326
///
315327
/// Defaults to [AlignmentDirectional.centerStart].
@@ -982,8 +994,10 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>> with WidgetsBin
982994
);
983995
}
984996

997+
// TODO(Ahmed): Use [WidgetStateMouseCursor.adaptiveClickable]
998+
// when it's supported by the min version of the package [Flutter>=3.41.0]
985999
final MouseCursor effectiveMouseCursor = WidgetStateProperty.resolveAs<MouseCursor>(
986-
WidgetStateMouseCursor.clickable,
1000+
widget.mouseCursor ?? WidgetStateMouseCursor.clickable,
9871001
<WidgetState>{
9881002
if (!_enabled) WidgetState.disabled,
9891003
},
@@ -1119,6 +1133,7 @@ class DropdownButtonFormField2<T> extends FormField<T> {
11191133
super.forceErrorText,
11201134
AutovalidateMode? autovalidateMode,
11211135
bool? enableFeedback,
1136+
MouseCursor? mouseCursor,
11221137
AlignmentGeometry alignment = AlignmentDirectional.centerStart,
11231138
FormFieldButtonStyleData? buttonStyleData,
11241139
IconStyleData iconStyleData = const IconStyleData(),
@@ -1211,6 +1226,7 @@ class DropdownButtonFormField2<T> extends FormField<T> {
12111226
focusNode: focusNode,
12121227
autofocus: autofocus,
12131228
enableFeedback: enableFeedback,
1229+
mouseCursor: mouseCursor,
12141230
alignment: alignment,
12151231
buttonStyleData: buttonStyleData?._toButtonStyleData,
12161232
iconStyleData: iconStyleData,

packages/dropdown_button2/lib/src/dropdown_menu_item.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ class _DropdownItemButtonState<T> extends State<_DropdownItemButton<T>> {
258258
enableFeedback: widget.enableFeedback,
259259
onTap: _handleOnTap,
260260
onFocusChange: _handleFocusChange,
261+
mouseCursor: _menuItemStyle.mouseCursor,
261262
borderRadius: _menuItemStyle.borderRadius,
262263
overlayColor: _menuItemStyle.overlayColor,
263264
child: isSelectedItem

packages/dropdown_button2/lib/src/dropdown_style_data.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ class MenuItemStyleData {
170170
this.useDecorationHorizontalPadding = false,
171171
this.borderRadius,
172172
this.overlayColor,
173+
this.mouseCursor,
173174
this.selectedMenuItemBuilder,
174175
});
175176

@@ -215,6 +216,15 @@ class MenuItemStyleData {
215216
/// <https://material.io/design/interaction/states.html#anatomy>.
216217
final WidgetStateProperty<Color?>? overlayColor;
217218

219+
/// The cursor for a mouse pointer when it enters or is hovering over a menu item.
220+
///
221+
/// {@macro flutter.material.InkWell.mouseCursor}
222+
///
223+
// TODO(Ahmed): Update to [WidgetStateMouseCursor.adaptiveClickable]
224+
// when it's supported by the min version of the package [Flutter>=3.41.0]
225+
/// If this property is null, [WidgetStateMouseCursor.clickable] will be used.
226+
final MouseCursor? mouseCursor;
227+
218228
/// A builder to customize the selected menu item.
219229
///
220230
/// If this callback is null, the selected menu item will be displayed as other [items].
@@ -237,12 +247,14 @@ class MenuItemStyleData {
237247
EdgeInsetsGeometry? padding,
238248
BorderRadius? borderRadius,
239249
WidgetStateProperty<Color?>? overlayColor,
250+
MouseCursor? mouseCursor,
240251
SelectedMenuItemBuilder? selectedMenuItemBuilder,
241252
}) {
242253
return MenuItemStyleData(
243254
padding: padding ?? this.padding,
244255
borderRadius: borderRadius ?? this.borderRadius,
245256
overlayColor: overlayColor ?? this.overlayColor,
257+
mouseCursor: mouseCursor ?? this.mouseCursor,
246258
selectedMenuItemBuilder: selectedMenuItemBuilder ?? this.selectedMenuItemBuilder,
247259
);
248260
}

0 commit comments

Comments
 (0)