From 08209b7e0b24b01308c864890a453d897fd0681a Mon Sep 17 00:00:00 2001 From: Justin McCandless Date: Thu, 22 Dec 2022 14:46:09 -0800 Subject: [PATCH] Explain how to test onSubmitted in its docs (#117550) * Explain how to test onSubmitted * Fix analyzer saying tester is undefined --- packages/flutter/lib/src/widgets/editable_text.dart | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/flutter/lib/src/widgets/editable_text.dart b/packages/flutter/lib/src/widgets/editable_text.dart index 448b9ec5bf..f5698a1a67 100644 --- a/packages/flutter/lib/src/widgets/editable_text.dart +++ b/packages/flutter/lib/src/widgets/editable_text.dart @@ -50,6 +50,7 @@ export 'package:flutter/services.dart' show SelectionChangedCause, SmartDashesTy // Examples can assume: // late BuildContext context; +// late WidgetTester tester; /// Signature for the callback that reports when the user changes the selection /// (including the cursor location). @@ -1233,6 +1234,18 @@ class EditableText extends StatefulWidget { /// By default, [onSubmitted] is called after [onChanged] when the user /// has finalized editing; or, if the default behavior has been overridden, /// after [onEditingComplete]. See [onEditingComplete] for details. + /// + /// ## Testing + /// The following is the recommended way to trigger [onSubmitted] in a test: + /// + /// ```dart + /// await tester.testTextInput.receiveAction(TextInputAction.done); + /// ``` + /// + /// Sending a `LogicalKeyboardKey.enter` via `tester.sendKeyEvent` will not + /// trigger [onSubmitted]. This is because on a real device, the engine + /// translates the enter key to a done action, but `tester.sendKeyEvent` sends + /// the key to the framework only. /// {@endtemplate} final ValueChanged? onSubmitted;