diff --git a/dev/integration_tests/ui/lib/keyboard_resize.dart b/dev/integration_tests/ui/lib/keyboard_resize.dart index 580a44570d..08d1d65d69 100644 --- a/dev/integration_tests/ui/lib/keyboard_resize.dart +++ b/dev/integration_tests/ui/lib/keyboard_resize.dart @@ -9,6 +9,7 @@ import 'keys.dart' as keys; void main() { enableFlutterDriverExtension( + enableTextEntryEmulation: false, handler: (String? message) async { // TODO(cbernaschina): remove when test flakiness is resolved return 'keyboard_resize'; @@ -46,21 +47,24 @@ class _MyHomePageState extends State { key: const Key(keys.kDefaultTextField), controller: _controller, focusNode: FocusNode(), + decoration: const InputDecoration(border: OutlineInputBorder()), ); return Scaffold( - body: Stack( - fit: StackFit.expand, - alignment: Alignment.bottomCenter, - children: [ - LayoutBuilder( - builder: (BuildContext context, BoxConstraints constraints) { - return Center( - child: Text('${constraints.biggest.height}', key: const Key(keys.kHeightText)), - ); - }, - ), - textField, - ], + body: SafeArea( + child: Stack( + fit: StackFit.expand, + alignment: Alignment.bottomCenter, + children: [ + LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + return Center( + child: Text('${constraints.biggest.height}', key: const Key(keys.kHeightText)), + ); + }, + ), + textField, + ], + ), ), floatingActionButton: FloatingActionButton( key: const Key(keys.kUnfocusButton), diff --git a/dev/integration_tests/ui/test_driver/keyboard_resize_test.dart b/dev/integration_tests/ui/test_driver/keyboard_resize_test.dart index bd46af7dcd..0b32e65239 100644 --- a/dev/integration_tests/ui/test_driver/keyboard_resize_test.dart +++ b/dev/integration_tests/ui/test_driver/keyboard_resize_test.dart @@ -19,7 +19,6 @@ void main() { }); test('Ensure keyboard dismissal resizes the view to original size', () async { - await driver.setTextEntryEmulation(enabled: false); final SerializableFinder heightText = find.byValueKey(keys.kHeightText); await driver.waitFor(heightText); @@ -29,11 +28,22 @@ void main() { // Focus the text field to show the keyboard. final SerializableFinder defaultTextField = find.byValueKey(keys.kDefaultTextField); await driver.waitFor(defaultTextField); - await driver.tap(defaultTextField); + + // The only practical way to detect the software keyboard opening or closing + // is to use polling and wait for the layout to change. + // We pick a short polling interval to speed up the test for most devices. + // In local tests, Pixel 8 Pro API 36 usually only one poll iteration is needed, + // older device like Galaxy Tab S3 API 28 takes 2-3 iterations. + const Duration pollDelay300Ms = Duration(milliseconds: 300); bool heightTextDidShrink = false; - for (int i = 0; i < 6; ++i) { - await Future.delayed(const Duration(seconds: 1)); + // TODO(harri35): Reconsider this polling duration when the root cause is found + // in https://github.com/flutter/flutter/issues/163606. + // Sometimes it can take up to 21.3 seconds for the keyboard to open, + // so we allow ample time here (200 * pollDelay300Ms = 60 sec) + for (int i = 0; i < 200; ++i) { + await driver.tap(defaultTextField); + await Future.delayed(pollDelay300Ms); // Measure the height with keyboard displayed. final String heightWithKeyboardShown = await driver.getText(heightText); if (double.parse(heightWithKeyboardShown) < double.parse(startHeight)) { @@ -49,8 +59,8 @@ void main() { await driver.tap(unfocusButton); bool heightTextDidExpand = false; - for (int i = 0; i < 3; ++i) { - await Future.delayed(const Duration(seconds: 1)); + for (int i = 0; i < 10; ++i) { + await Future.delayed(pollDelay300Ms); // Measure the final height. final String endHeight = await driver.getText(heightText); if (endHeight == startHeight) {