@@ -88,7 +88,16 @@ extension KeyboardInput on WidgetTester {
88
88
89
89
/// Simulates the user pressing ENTER in a widget attached to the IME.
90
90
///
91
- /// Instead of key events, this method generates a "\n" insertion followed by a TextInputAction.newline.
91
+ /// Instead of key events, this method generates a `\n` insertion followed by a `TextInputAction.newline` .
92
+ ///
93
+ /// {@template newline_quirks_mode}
94
+ /// WARNING: On Android Web, and seemingly only Android Web, we've observed that the standard behavior is
95
+ /// to send a newline `\n` , but not a `TextInputAction.newline` . Because this behavior is an outlier, we believe
96
+ /// it's likely some kind of bug. Rather than always implement this behavior for Android Web, this method
97
+ /// has a [useQuirksMode] parameter. When [useQuirksMode] is `true` , no `TextInputAction.newline` is dispatched
98
+ /// for Android Web, but when its `false` , a `\n` AND a `TextInputAction.newline` are both dispatched, regardless
99
+ /// of platform.
100
+ /// {@endtemplate}
92
101
///
93
102
/// {@template ime_client_getter}
94
103
/// The given [finder] must find a [StatefulWidget] whose [State] implements
@@ -102,6 +111,7 @@ extension KeyboardInput on WidgetTester {
102
111
GetDeltaTextInputClient ? getter,
103
112
bool settle = true ,
104
113
int extraPumps = 0 ,
114
+ bool useQuirksMode = true ,
105
115
}) async {
106
116
if (! testTextInput.hasAnyClients) {
107
117
// There isn't any IME connections.
@@ -110,8 +120,15 @@ extension KeyboardInput on WidgetTester {
110
120
111
121
await ime.typeText ('\n ' , finder: finder, getter: getter);
112
122
await pump ();
113
- await testTextInput.receiveAction (TextInputAction .newline);
114
- await pump ();
123
+
124
+ // On any platform, except Android Web, we want to dispatch `TextInputAction.newline`
125
+ // in addition to the newline `\n`. However, on Android Web, when quirks mode is
126
+ // activated, we don't want to send a `TextInputAction.newline` because we've observed
127
+ // that in the real world, Android Web doesn't dispatch a `TextInputAction.newline`.
128
+ if (_keyEventPlatform != "android" || ! kIsWeb || ! useQuirksMode) {
129
+ await testTextInput.receiveAction (TextInputAction .newline);
130
+ await pump ();
131
+ }
115
132
116
133
await _maybeSettleOrExtraPumps (settle: settle, extraPumps: extraPumps);
117
134
}
@@ -122,12 +139,17 @@ extension KeyboardInput on WidgetTester {
122
139
/// then this method simulates pressing the newline action button on a software keyboard, which inserts "/n"
123
140
/// into the text, and also sends a NEWLINE action to the IME client.
124
141
///
142
+ /// Pressing ENTER through the IME has some quirks:
143
+ ///
144
+ /// {@macro newline_quirks_mode}
145
+ ///
125
146
/// {@macro ime_client_getter}
126
147
Future <void > pressEnterAdaptive ({
127
148
Finder ? finder,
128
149
GetDeltaTextInputClient ? getter,
129
150
bool settle = true ,
130
151
int extraPumps = 0 ,
152
+ bool useQuirksMode = true ,
131
153
}) async {
132
154
final handled = await sendKeyEvent (LogicalKeyboardKey .enter, platform: _keyEventPlatform);
133
155
if (handled) {
@@ -137,7 +159,13 @@ extension KeyboardInput on WidgetTester {
137
159
return ;
138
160
}
139
161
140
- await pressEnterWithIme (finder: finder, getter: getter, settle: settle, extraPumps: extraPumps);
162
+ await pressEnterWithIme (
163
+ finder: finder,
164
+ getter: getter,
165
+ settle: settle,
166
+ extraPumps: extraPumps,
167
+ useQuirksMode: useQuirksMode,
168
+ );
141
169
}
142
170
143
171
/// Simulates pressing the SPACE key.
0 commit comments