Unverified Commit 29bfb11c authored by Michael Klimushyn's avatar Michael Klimushyn Committed by GitHub

Partial deflaking of abstract_method_smoke_test (#42379)

1. The platform code to show the keyboard wasn't working on certain
devices. From my testing it appears to be related to when the code was
firing. IMM won't show the soft input (or shows and then immediately
hides it, it's hard to tell) if it's called before the Flutter UI is
loaded. Change this to instead show the soft keyboard after a message
from Flutter that main() has been started.

2. A text field was visible in the UI, and the test was run under a
fuzzer that random tapped portions of the screen. Remove the text field
so that the fuzzer can't accidentally open the keyboard on its own at a
random time.

3. The keyboard was left open even after the app was closed. Also toggle
the input off when the app was closed, so that this test can be ran
multiple times in succession relatively hermetically.
parent ff15a39c
......@@ -4,6 +4,8 @@ import android.content.Context
import android.os.Bundle
import android.view.inputmethod.InputMethodManager
import io.flutter.app.FlutterActivity
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity: FlutterActivity() {
......@@ -12,8 +14,22 @@ class MainActivity: FlutterActivity() {
GeneratedPluginRegistrant.registerWith(this)
// Triggers the Android keyboard, which causes the resize of the Flutter view.
// https://github.com/flutter/flutter/issues/40126
// We need to wait for the app to complete.
MethodChannel(getFlutterView(), "com.example.abstract_method_smoke_test")
.setMethodCallHandler({ call, result ->
toggleInput()
result.success(null)
})
}
override fun onPause() {
// Hide the input when the app is closed.
toggleInput()
super.onPause()
}
fun toggleInput() {
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0)
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0)
}
}
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
void main() {
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
const MethodChannel channel = MethodChannel('com.example.abstract_method_smoke_test');
await channel.invokeMethod<void>('show_keyboard');
runApp(MyApp());
print('Test suceeded');
}
......@@ -48,9 +52,8 @@ class SecondPage extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: <Widget>[
TextFormField(),
const Expanded(
children: const <Widget>[
Expanded(
child: GoogleMap(
initialCameraPosition: CameraPosition(
target: LatLng(0, 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment