Horizontally expand text selection toolbar buttons in overflow menu (#144391)
## Description This PR expands the items displayed in the overflow menu of a `TextSelectionToolbar` making buttons clickable in the blank area. | Before | After | |--------|--------| | Each item has its own width | All items expand horizontally | |  |  | ## Related Issue Fixes https://github.com/flutter/flutter/issues/144089. ## Tests Adds 1 tests.
This commit is contained in:
@@ -262,6 +262,7 @@ class AdaptiveTextSelectionToolbar extends StatelessWidget {
|
||||
buttons.add(TextSelectionToolbarTextButton(
|
||||
padding: TextSelectionToolbarTextButton.getPadding(i, buttonItems.length),
|
||||
onPressed: buttonItem.onPressed,
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: Text(getButtonLabel(context, buttonItem)),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -267,6 +267,7 @@ class _TextSelectionControlsToolbarState extends State<_TextSelectionControlsToo
|
||||
children: itemDatas.asMap().entries.map((MapEntry<int, _TextSelectionToolbarItemData> entry) {
|
||||
return TextSelectionToolbarTextButton(
|
||||
padding: TextSelectionToolbarTextButton.getPadding(entry.key, itemDatas.length),
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
onPressed: entry.value.onPressed,
|
||||
child: Text(entry.value.label),
|
||||
);
|
||||
|
||||
@@ -569,6 +569,40 @@ class _RenderTextSelectionToolbarItemsLayout extends RenderBox with ContainerRen
|
||||
size = nextSize;
|
||||
}
|
||||
|
||||
// Horizontally expand the children when the menu overflows so they can react to
|
||||
// pointer events into their whole area.
|
||||
void _resizeChildrenWhenOverflow() {
|
||||
if (!overflowOpen) {
|
||||
return;
|
||||
}
|
||||
|
||||
final RenderBox navButton = firstChild!;
|
||||
int i = -1;
|
||||
|
||||
visitChildren((RenderObject renderObjectChild) {
|
||||
final RenderBox child = renderObjectChild as RenderBox;
|
||||
final ToolbarItemsParentData childParentData = child.parentData! as ToolbarItemsParentData;
|
||||
|
||||
i++;
|
||||
|
||||
// Ignore the navigation button.
|
||||
if (renderObjectChild == navButton) {
|
||||
return;
|
||||
}
|
||||
|
||||
// There is no need to update children that won't be painted.
|
||||
if (!_shouldPaintChild(renderObjectChild, i)) {
|
||||
childParentData.shouldPaint = false;
|
||||
return;
|
||||
}
|
||||
|
||||
child.layout(
|
||||
BoxConstraints.tightFor(width: size.width),
|
||||
parentUsesSize: true,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void performLayout() {
|
||||
_lastIndexThatFits = -1;
|
||||
@@ -579,6 +613,7 @@ class _RenderTextSelectionToolbarItemsLayout extends RenderBox with ContainerRen
|
||||
|
||||
_layoutChildren();
|
||||
_placeChildren();
|
||||
_resizeChildrenWhenOverflow();
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user