Skip to content

Commit 90badf7

Browse files
Add send_text_input_action case to deserialization_factory to allow sendTextInputAction usages through flutter_driver. (#139197)
**As a follow up to flutter/flutter#131776 **Summary:** Previously in flutter/flutter#106561, SendTextInputAction was added to Flutter Driver. But it still cannot be used from flutter_driver tests. This PR intends to resolve that issue. **Issue:** An `DriverError: Unsupported command kind send_text_input_action` would be thrown from `flutter_driver/lib/src/common/deserialization_factory.dart` when a call to `driver.sendTextInputAction(TextInputAction.done);` was made despite the method `sendTextInputAction` is available for use since flutter/flutter#106561. Previous works has been done in flutter/flutter#131776, I merely added tests. Best regards.
1 parent cb50d4a commit 90badf7

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

packages/flutter_driver/lib/src/common/deserialization_factory.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import 'render_tree.dart';
1515
import 'request_data.dart';
1616
import 'semantics.dart';
1717
import 'text.dart';
18+
import 'text_input_action.dart';
1819
import 'wait.dart';
1920

2021
/// A factory for deserializing [Finder]s.
@@ -46,6 +47,7 @@ mixin DeserializeCommandFactory {
4647
case 'get_layer_tree': return GetLayerTree.deserialize(params);
4748
case 'get_render_tree': return GetRenderTree.deserialize(params);
4849
case 'enter_text': return EnterText.deserialize(params);
50+
case 'send_text_input_action': return SendTextInputAction.deserialize(params);
4951
case 'get_text': return GetText.deserialize(params, finderFactory);
5052
case 'request_data': return RequestData.deserialize(params);
5153
case 'scroll': return Scroll.deserialize(params, finderFactory);

packages/flutter_driver/test/src/real_tests/extension_test.dart

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
library;
1111

1212
import 'package:flutter/foundation.dart';
13-
import 'package:flutter/material.dart';
13+
import 'package:flutter/material.dart' hide TextInputAction;
1414
import 'package:flutter/rendering.dart';
1515
import 'package:flutter/scheduler.dart';
16-
import 'package:flutter/services.dart';
16+
import 'package:flutter/services.dart' hide TextInputAction;
1717
import 'package:flutter_driver/flutter_driver.dart';
1818
import 'package:flutter_driver/src/extension/extension.dart';
19-
import 'package:flutter_test/flutter_test.dart';
19+
import 'package:flutter_test/flutter_test.dart' hide TextInputAction;
2020

2121
import 'stubs/stub_command.dart';
2222
import 'stubs/stub_command_extension.dart';
@@ -1245,4 +1245,41 @@ void main() {
12451245
);
12461246
});
12471247
});
1248+
1249+
group('sendTextInputAction', () {
1250+
late FlutterDriverExtension driverExtension;
1251+
1252+
Future<void> sendAction(TextInputAction action) async {
1253+
final Map<String, String> arguments = SendTextInputAction(action).serialize();
1254+
await driverExtension.call(arguments);
1255+
}
1256+
1257+
MaterialApp testWidget(TextEditingController controller) => MaterialApp(
1258+
home: Material(
1259+
child: Center(
1260+
child: TextField(
1261+
key: const ValueKey<String>('foo'),
1262+
autofocus: true,
1263+
controller: controller,
1264+
onSubmitted: (_) {
1265+
controller.value = const TextEditingValue(text: 'bar');
1266+
},
1267+
),
1268+
),
1269+
),
1270+
);
1271+
1272+
testWidgets('press done trigger onSubmitted and change value', (WidgetTester tester) async {
1273+
driverExtension = FlutterDriverExtension((String? arg) async => '', true, true);
1274+
1275+
final TextEditingController controller = TextEditingController(
1276+
text: 'foo',
1277+
);
1278+
await tester.pumpWidget(testWidget(controller));
1279+
1280+
expect(controller.value.text, 'foo');
1281+
await sendAction(TextInputAction.done);
1282+
expectSync(controller.value.text, 'bar');
1283+
});
1284+
});
12481285
}

0 commit comments

Comments
 (0)