Double double tap toggles instead of error (#33802)

Fix exception that was happening when double-double-tapping a TextField (or double long tapping).
This commit is contained in:
Justin McCandless 2019-06-04 10:39:08 -07:00 committed by GitHub
parent c482edac4f
commit a35d6615ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 74 additions and 6 deletions

View File

@ -744,8 +744,9 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
from: details.globalPosition,
cause: SelectionChangedCause.forcePress,
);
if (_shouldShowSelectionToolbar)
_editableTextKey.currentState.showToolbar();
if (_shouldShowSelectionToolbar) {
_editableTextKey.currentState.toggleToolbar();
}
}
}
@ -812,15 +813,18 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
}
void _handleSingleLongTapEnd(LongPressEndDetails details) {
if (_shouldShowSelectionToolbar)
_editableTextKey.currentState.showToolbar();
if (widget.selectionEnabled) {
if (_shouldShowSelectionToolbar)
_editableTextKey.currentState.toggleToolbar();
}
}
void _handleDoubleTapDown(TapDownDetails details) {
if (widget.selectionEnabled) {
_renderEditable.selectWord(cause: SelectionChangedCause.doubleTap);
if (_shouldShowSelectionToolbar)
_editableTextKey.currentState.showToolbar();
if (_shouldShowSelectionToolbar) {
_editableText.toggleToolbar();
}
}
}

View File

@ -5220,6 +5220,70 @@ void main() {
},
);
testWidgets(
'double double tap toggles selection menu',
(WidgetTester tester) async {
final TextEditingController controller = TextEditingController(
text: '',
);
await tester.pumpWidget(
MaterialApp(
home: Material(
child: Center(
child: TextField(
controller: controller,
),
),
),
),
);
// Double tap on the same location shows the selection menu.
await tester.tapAt(textOffsetToPosition(tester, 0));
await tester.pump(const Duration(milliseconds: 50));
await tester.tapAt(textOffsetToPosition(tester, 0));
await tester.pump();
expect(find.text('PASTE'), findsOneWidget);
// Double tap again hides the selection menu.
await tester.tapAt(textOffsetToPosition(tester, 0));
await tester.pump(const Duration(milliseconds: 50));
await tester.tapAt(textOffsetToPosition(tester, 0));
await tester.pump();
expect(find.text('PASTE'), findsNWidgets(0));
},
);
testWidgets(
'double long press toggles selection menu',
(WidgetTester tester) async {
final TextEditingController controller = TextEditingController(
text: '',
);
await tester.pumpWidget(
MaterialApp(
home: Material(
child: Center(
child: TextField(
controller: controller,
),
),
),
),
);
// Long press shows the selection menu.
await tester.longPressAt(textOffsetToPosition(tester, 0));
await tester.pump();
expect(find.text('PASTE'), findsOneWidget);
// Double tap again hides the selection menu.
await tester.longPressAt(textOffsetToPosition(tester, 0));
await tester.pump();
expect(find.text('PASTE'), findsNWidgets(0));
},
);
testWidgets(
'double tap hold selects word (iOS)',
(WidgetTester tester) async {