Unverified Commit 2f45458e authored by hangyu's avatar hangyu Committed by GitHub

Fix a null crash in SelectableRegion Widget (#124736)

issue #123378
parent df8d8194
......@@ -1301,13 +1301,13 @@ class _SelectableRegionContainerDelegate extends MultiSelectableSelectionContain
}
void _updateLastEdgeEventsFromGeometries() {
if (currentSelectionStartIndex != -1) {
if (currentSelectionStartIndex != -1 && selectables[currentSelectionStartIndex].value.hasSelection) {
final Selectable start = selectables[currentSelectionStartIndex];
final Offset localStartEdge = start.value.startSelectionPoint!.localPosition +
Offset(0, - start.value.startSelectionPoint!.lineHeight / 2);
_lastStartEdgeUpdateGlobalPosition = MatrixUtils.transformPoint(start.getTransformTo(null), localStartEdge);
}
if (currentSelectionEndIndex != -1) {
if (currentSelectionEndIndex != -1 && selectables[currentSelectionEndIndex].value.hasSelection) {
final Selectable end = selectables[currentSelectionEndIndex];
final Offset localEndEdge = end.value.endSelectionPoint!.localPosition +
Offset(0, -end.value.endSelectionPoint!.lineHeight / 2);
......
......@@ -38,6 +38,37 @@ void main() {
}
}, variant: TargetPlatformVariant.all());
testWidgets('Does not crash when long pressing on padding after dragging', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/123378
await tester.pumpWidget(
const MaterialApp(
color: Color(0xFF2196F3),
title: 'Demo',
home: Scaffold(
body: SelectionArea(
child: Padding(
padding: EdgeInsets.all(100.0),
child: Text('Hello World'),
),
),
),
),
);
final TestGesture dragging = await tester.startGesture(const Offset(10, 10));
addTearDown(dragging.removePointer);
await tester.pump(const Duration(milliseconds: 500));
await dragging.moveTo(const Offset(90, 90));
await dragging.up();
final TestGesture longpress = await tester.startGesture(const Offset(20,20));
addTearDown(longpress.removePointer);
await tester.pump(const Duration(milliseconds: 500));
await longpress.up();
expect(tester.takeException(), isNull);
});
testWidgets('builds the default context menu by default', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment