@@ -51,6 +51,34 @@ extension KeyboardInput on WidgetTester {
51
51
}
52
52
}
53
53
54
+ /// Runs [sendKeyEvent] , using the current [defaultTargetPlatform] as the key simulators `platform` value.
55
+ ///
56
+ /// {@template flutter_key_simulation_override}
57
+ /// This method was created because developers often use convenience methods in this package,
58
+ /// along with Flutter's standard simulation methods. But, the convenience methods in this package
59
+ /// simulate a key press `platform` based on the current [defaultTargetPlatform] , whereas Flutter's
60
+ /// standard simulation methods always default to "android". Using mismatched platforms across
61
+ /// key simulations leads to unexpected results. By always using methods in this package, instead of
62
+ /// standard Flutter methods, the simulated platform is guaranteed to match across calls, and also
63
+ /// match the platform that's simulated within the surrounding test, i.e., [defaultTargetPlatform] .
64
+ /// @{endtemplate}
65
+ Future <void > pressKey (LogicalKeyboardKey key) => sendKeyEvent (key, platform: _keyEventPlatform);
66
+
67
+ /// Runs [simulateKeyDownEvent] , using the current [defaultTargetPlatform] as the key simulators `platform` value.
68
+ ///
69
+ /// {@macro flutter_key_simulation_override}
70
+ Future <void > pressKeyDown (LogicalKeyboardKey key) => simulateKeyDownEvent (key, platform: _keyEventPlatform);
71
+
72
+ /// Runs [simulateKeyUpEvent] , using the current [defaultTargetPlatform] as the key simulators `platform` value.
73
+ ///
74
+ /// {@macro flutter_key_simulation_override}
75
+ Future <void > releaseKeyUp (LogicalKeyboardKey key) => simulateKeyUpEvent (key, platform: _keyEventPlatform);
76
+
77
+ /// Runs [simulateKeyRepeatEvent] , using the current [defaultTargetPlatform] as the key simulators `platform` value.
78
+ ///
79
+ /// {@macro flutter_key_simulation_override}
80
+ Future <void > repeatKey (LogicalKeyboardKey key) => simulateKeyRepeatEvent (key, platform: _keyEventPlatform);
81
+
54
82
Future <void > pressEnter () async {
55
83
await sendKeyEvent (LogicalKeyboardKey .enter, platform: _keyEventPlatform);
56
84
await pumpAndSettle ();
0 commit comments