【问题标题】:Flutter Webview - Keyboard does not close automaticallyFlutter Webview - 键盘不会自动关闭
【发布时间】:2020-12-15 21:18:06
【问题描述】:

当我点击输入框时键盘会自动打开,但是当我按下okay或其他地方时,键盘不会自动关闭。如何在失去焦点时隐藏软键盘?

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,
          );
        }),
      ),
    );
  }
}

我将下面的代码块添加到我的代码中,但它不起作用。 Webview 保持在白屏上。

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

screen shot

【问题讨论】:

    标签: flutter dart webview


    【解决方案1】:

    您是否在 Android 模拟器上进行测试?

    尝试使用混合构图

    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,
              );
            }),
          ),
        );
      }
    }
    

    WebView 依赖于 Platform Views 来嵌入 Android 的 Flutter 应用程序中的 webview。默认情况下,基于虚拟显示 使用平台视图后端,该实现有多个 键盘。当需要键盘输入时,我们建议使用 基于混合合成的平台视图实现

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

    【讨论】:

    • 我尝试添加此代码块。但是,它在任何设备上都不起作用。当我使用导航栏切换到另一个 Webview 时,会显示空白页面并且无法打开网页。
    猜你喜欢
    • 2021-03-29
    • 1970-01-01
    • 1970-01-01
    • 2015-12-19
    • 2011-09-19
    • 1970-01-01
    • 2023-03-23
    • 2011-03-21
    • 2020-04-28
    相关资源
    最近更新 更多