Fix CupertinoTextSelectionToolbar showing unnecessary pagination (#104587)
This commit is contained in:
@@ -103,7 +103,7 @@ class CupertinoTextSelectionToolbar extends StatelessWidget {
|
||||
/// default Cupertino toolbar.
|
||||
final CupertinoToolbarBuilder toolbarBuilder;
|
||||
|
||||
// Add the visial vertical line spacer between children buttons.
|
||||
// Add the visual vertical line spacer between children buttons.
|
||||
static List<Widget> _addChildrenSpacers(List<Widget> children) {
|
||||
final List<Widget> nextChildren = <Widget>[];
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
@@ -801,8 +801,9 @@ class _RenderCupertinoTextSelectionToolbarItems extends RenderBox with Container
|
||||
double paginationButtonsWidth = 0.0;
|
||||
if (currentPage == 0) {
|
||||
// If this is the last child, it's ok to fit without a forward button.
|
||||
// Note childCount doesn't include slotted children which come before the list ones.
|
||||
paginationButtonsWidth =
|
||||
i == childCount - 1 ? 0.0 : _nextButton!.size.width;
|
||||
i == childCount + 2 ? 0.0 : _nextButton!.size.width;
|
||||
} else {
|
||||
paginationButtonsWidth = subsequentPageButtonsWidth;
|
||||
}
|
||||
|
||||
@@ -181,6 +181,33 @@ void main() {
|
||||
expect(findOverflowBackButton(), findsNothing);
|
||||
}, skip: kIsWeb); // [intended] We do not use Flutter-rendered context menu on the Web.
|
||||
|
||||
testWidgets('does not paginate if children fit with zero margin', (WidgetTester tester) async {
|
||||
final List<Widget> children = List<Widget>.generate(7, (int i) => const TestBox());
|
||||
final double spacerWidth = 1.0 / tester.binding.window.devicePixelRatio;
|
||||
final double dividerWidth = 1.0 / tester.binding.window.devicePixelRatio;
|
||||
const double borderRadius = 8.0; // Should match _kToolbarBorderRadius
|
||||
final double width = 7 * TestBox.itemWidth + 6 * (dividerWidth + 2 * spacerWidth) + 2 * borderRadius;
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(
|
||||
home: Center(
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
child: CupertinoTextSelectionToolbar(
|
||||
anchorAbove: const Offset(50.0, 100.0),
|
||||
anchorBelow: const Offset(50.0, 200.0),
|
||||
children: children,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// All children fit on the screen, so they are all rendered.
|
||||
expect(find.byType(TestBox), findsNWidgets(children.length));
|
||||
expect(findOverflowNextButton(), findsNothing);
|
||||
expect(findOverflowBackButton(), findsNothing);
|
||||
}, skip: kIsWeb); // [intended] We do not use Flutter-rendered context menu on the Web.
|
||||
|
||||
testWidgets('positions itself at anchorAbove if it fits', (WidgetTester tester) async {
|
||||
late StateSetter setState;
|
||||
const double height = _kToolbarHeight;
|
||||
|
||||
Reference in New Issue
Block a user