Skip to content

Commit 4a1002e

Browse files
authored
Fix selection toolbar not showing on drag end (#121110)
1 parent 1fb2158 commit 4a1002e

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

packages/flutter/lib/src/widgets/selectable_region.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ class SelectableRegionState extends State<SelectableRegion> with TextSelectionDe
537537
} else {
538538
_selectionOverlay!.hideMagnifier();
539539
_selectionOverlay!.showToolbar(
540+
context: context,
540541
contextMenuBuilder: (BuildContext context) {
541542
return widget.contextMenuBuilder!(context, this);
542543
},

packages/flutter/test/material/selection_area_test.dart

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,53 @@ void main() {
129129
expect(content, isNotNull);
130130
expect(content!.plainText, 'How');
131131
});
132+
133+
testWidgets('stopping drag of end handle will show the toolbar', (WidgetTester tester) async {
134+
// Regression test for https://github.com/flutter/flutter/issues/119314
135+
await tester.pumpWidget(
136+
MaterialApp(
137+
home: Scaffold(
138+
body: Padding(
139+
padding: const EdgeInsets.only(top: 64),
140+
child: Column(
141+
children: <Widget>[
142+
const Text('How are you?'),
143+
SelectionArea(
144+
focusNode: FocusNode(),
145+
child: const Text('Good, and you?'),
146+
),
147+
const Text('Fine, thank you.'),
148+
],
149+
),
150+
),
151+
),
152+
),
153+
);
154+
final RenderParagraph paragraph2 = tester.renderObject<RenderParagraph>(find.descendant(of: find.text('Good, and you?'), matching: find.byType(RichText)));
155+
final TestGesture gesture = await tester.startGesture(textOffsetToPosition(paragraph2, 7)); // at the 'a'
156+
addTearDown(gesture.removePointer);
157+
await tester.pump(const Duration(milliseconds: 500));
158+
await gesture.up();
159+
final List<TextBox> boxes = paragraph2.getBoxesForSelection(paragraph2.selections[0]);
160+
expect(boxes.length, 1);
161+
// There is a selection now.
162+
// We check the presence of the copy button to make sure the selection toolbar
163+
// is showing.
164+
expect(find.text('Copy'), findsOneWidget);
165+
166+
// This is the position of the selection handle displayed at the end.
167+
final Offset handlePos = paragraph2.localToGlobal(boxes[0].toRect().bottomRight);
168+
await gesture.down(handlePos);
169+
await gesture.moveTo(textOffsetToPosition(paragraph2, 11) + Offset(0, paragraph2.size.height / 2));
170+
await tester.pump();
171+
172+
await gesture.up();
173+
await tester.pump();
174+
175+
// After lifting the finger up, the selection toolbar should be showing again.
176+
expect(find.text('Copy'), findsOneWidget);
177+
},
178+
variant: TargetPlatformVariant.all(),
179+
skip: kIsWeb, // [intended]
180+
);
132181
}

0 commit comments

Comments
 (0)