You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue
When creating a new DropdownItem it should be possible to assign a focusNode instead of making the package define it for each item in the menu.
Developers need to access item's focus node in order to achive custom behaviour and at the moment it is not possibile.
Proposal
Accept FocusNode? focusNode as constructor parameter for DropdownItem.
Below an idea of what the code should look like:
classDropdownItem<T> extends_DropdownMenuItemContainer {
/// Creates a dropdown item. /// /// The [child] property must be set.constDropdownItem({
requiredsuper.child,
super.height,
super.intrinsicHeight,
super.alignment,
this.onTap,
this.value,
this.enabled =true,
this.closeOnTap =true,
this.focusNode,
super.key,
});
/// Called when the dropdown menu item is tapped.finalVoidCallback? onTap;
/// Called when the dropdown menu item is tapped.finalFocusNode? focusNode;
/// The value to return if the user selects this menu item. /// /// Eventually returned in a call to [DropdownButton.onChanged].finalT? value;
/// Whether or not a user can select this menu item. /// /// Defaults to `true`.finalbool enabled;
/// Whether the dropdown should close when the item is tapped. /// /// Defaults to true.finalbool closeOnTap;
/// Creates a copy of this DropdownItem but with the given fields replaced with the new values.DropdownItem<T> copyWith({
Widget? child,
double? height,
bool? intrinsicHeight,
voidFunction()? onTap,
T? value,
bool? enabled,
AlignmentGeometry? alignment,
bool? closeOnTap,
FocusNode? focusNode,
}) {
returnDropdownItem<T>(
height: height ??this.height,
intrinsicHeight: intrinsicHeight ??this.intrinsicHeight,
onTap: onTap ??this.onTap,
value: value ??this.value,
enabled: enabled ??this.enabled,
alignment: alignment ??this.alignment,
closeOnTap: closeOnTap ??this.closeOnTap,
focusNode: focusNode,
child: child ??this.child,
);
}
}
And it should be passed by _DropdownItemButton to the proper InkWell, as my understanding it should be something like this but didn't try it as a solution.
If you have any other ways in order to achive custom usage of items focusNode please reach me out here.
class_DropdownItemButtonState<T> extendsState<_DropdownItemButton<T>> {
void_handleFocusChange(bool focused) {
finalbool inTraditionalMode;
switch (FocusManager.instance.highlightMode) {
caseFocusHighlightMode.touch:
inTraditionalMode =false;
// TODO(Ahmed): Remove decorative breaks and add lint to it [flutter>=v3.10.0].break;
caseFocusHighlightMode.traditional:
inTraditionalMode =true;
break;
}
if (focused && inTraditionalMode) {
final_MenuLimits menuLimits = widget.route.getMenuLimits(
widget.buttonRect,
widget.constraints.maxHeight,
widget.mediaQueryPadding,
widget.itemIndex,
);
widget.route.scrollController!.animateTo(
menuLimits.scrollOffset,
curve:Curves.easeInOut,
duration:constDuration(milliseconds:100),
);
}
}
void_handleOnTap() {
finalDropdownItem<T> dropdownItem = widget.route.items[widget.itemIndex];
dropdownItem.onTap?.call();
if (dropdownItem.closeOnTap) {
Navigator.pop(
context,
_DropdownRouteResult<T>(dropdownItem.value),
);
}
}
staticconstMap<ShortcutActivator, Intent> _webShortcuts =<ShortcutActivator, Intent>{
// On the web, up/down don't change focus, *except* in a <select>// element, which is what a dropdown emulates.SingleActivator(LogicalKeyboardKey.arrowDown):DirectionalFocusIntent(TraversalDirection.down),
SingleActivator(LogicalKeyboardKey.arrowUp):DirectionalFocusIntent(TraversalDirection.up),
};
MenuItemStyleDataget menuItemStyle => widget.route.menuItemStyle;
@overrideWidgetbuild(BuildContext context) {
finaldouble menuCurveEnd = widget.route.dropdownStyle.openInterval.end;
finalDropdownItem<T> dropdownItem = widget.route.items[widget.itemIndex];
finaldouble unit =0.5/ (widget.route.items.length +1.5);
finaldouble start =_clampDouble(menuCurveEnd + (widget.itemIndex +1) * unit, 0.0, 1.0);
finaldouble end =_clampDouble(start +1.5* unit, 0.0, 1.0);
finalCurvedAnimation opacity =CurvedAnimation(
parent: widget.route.animation!, curve:Interval(start, end));
Widget child =Container(
padding: (menuItemStyle.padding ?? _kMenuItemPadding)
.resolve(widget.textDirection),
child: dropdownItem,
);
// An [InkWell] is added to the item only if it is enabled// isNoSelectedItem to avoid first item highlight when no item selectedif (dropdownItem.enabled) {
finalbool isSelectedItem =!widget.route.isNoSelectedItem &&
widget.itemIndex == widget.route.selectedIndex;
child =InkWell(
focusNode: dropdownItem.focusNode,
autofocus: isSelectedItem,
enableFeedback: widget.enableFeedback,
onTap: _handleOnTap,
onFocusChange: _handleFocusChange,
borderRadius: menuItemStyle.borderRadius,
overlayColor: menuItemStyle.overlayColor,
child: isSelectedItem
? menuItemStyle.selectedMenuItemBuilder?.call(context, child) ??
child
: child,
);
}
child =FadeTransition(opacity: opacity, child: child);
if (kIsWeb && dropdownItem.enabled) {
child =Shortcuts(
shortcuts: _webShortcuts,
child: child,
);
}
return child;
}
}
The text was updated successfully, but these errors were encountered:
Issue
When creating a new DropdownItem it should be possible to assign a focusNode instead of making the package define it for each item in the menu.
Developers need to access item's focus node in order to achive custom behaviour and at the moment it is not possibile.
Proposal
Accept FocusNode? focusNode as constructor parameter for DropdownItem.
Below an idea of what the code should look like:
And it should be passed by _DropdownItemButton to the proper InkWell, as my understanding it should be something like this but didn't try it as a solution.
If you have any other ways in order to achive custom usage of items focusNode please reach me out here.
The text was updated successfully, but these errors were encountered: