0

The keyboard automatically opens when I click on a input box, but when I press okay or elsewhere, the keyboard does not automatically close. How can I hide soft keyboard on losing focus?

class _ExampleState extends State<Example> {

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      child: Scaffold(
        body: Builder(builder: (BuildContext context) {
          return WebView(
            initialUrl: 'https://google.com',
            javascriptMode: JavascriptMode.unrestricted,
          );
        }),
      ),
    );
  }
}

I added the code block below to my code, but it didn't work. Webview remained on the white screen.

  @override
  void initState() {
    super.initState();
    // Enable hybrid composition.
    if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
  }

screen shot

1 Answer 1

0

Are you testing on an Android emulator?

Try to use Hybrid composition

class _ExampleState extends State<Example> {

  @override
  void initState() {
    super.initState();
    // Enable hybrid composition.
    if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
  }

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      child: Scaffold(
        body: Builder(builder: (BuildContext context) {
          return WebView(
            initialUrl: 'https://google.com',
            javascriptMode: JavascriptMode.unrestricted,
          );
        }),
      ),
    );
  }
}

The WebView is relying on Platform Views to embed the Android’s webview within the Flutter app. By default a Virtual Display based platform view backend is used, this implementation has multiple keyboard. When keyboard input is required we recommend using the Hybrid Composition based platform views implementation

https://github.com/flutter/plugins/tree/master/packages/webview_flutter#using-hybrid-composition

Sign up to request clarification or add additional context in comments.

1 Comment

I tried to add this code block. But, it didn't work in any devices. When I switch to another Webview with the navigation bar, the blank page is shown and the web page does not open.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.