【问题标题】:How to prevent keyboard from popping in a flutter webview如何防止键盘在颤动的网页视图中弹出
【发布时间】:2019-11-26 02:07:46
【问题描述】:

我的应用程序的一部分包括访问网页并在 web 视图中显示它。由于此应用程序可能用于条码扫描,因此我想防止在用户单击 WEBVIEW 中的文本字段时弹出键盘。

我还想要一些关于如何创建一个按钮的指导,该按钮在我的应用程序中始终存在于所有 web 视图中,按下该按钮将弹出键盘。如果未按下此按钮,即使单击任何 webview 中的任何文本字段,键盘也不应弹出。

提前致谢!

下面是实现网页的类的代码:

import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';

class WebViewWebPage extends StatelessWidget {
  final String url;

  WebViewWebPage({this.url});

  @override
  Widget build(BuildContext context) {
    return WebviewScaffold(
      url: url,
      hidden: false,
      appBar: AppBar(title: Text("Open Web Page URL in webview")),
    );
  }
}

【问题讨论】:

  • 看看这个link。简单明了。
  • 谢谢。我在返回 WebviewScaffold 之前添加了 'SystemChannels.textInput.invokeMethod('TextInput.hide')' 并且它有效。但是,我想在我的应用栏中添加一个按钮,该按钮将允许使用 TextInput.show 显示键盘,但上面提到的语句仍然阻止显示键盘。我该如何解决这个问题?

标签: flutter


【解决方案1】:

对于持久按钮,请尝试https://api.flutter.dev/flutter/material/FloatingActionButton-class.html

Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: Text('Floating Action Button Sample'),
    ),
    body: Center(
      child: Text('Press the button below!')
    ),
    floatingActionButton: FloatingActionButton(
      onPressed: () {
        // Add your onPressed code here!
      },
      child: Icon(Icons.thumb_up),
      backgroundColor: Colors.pink,
    ),
  );
}

您可以将图标更改为键盘https://api.flutter.dev/flutter/material/Icons/keyboard-constant.html

【讨论】:

    猜你喜欢
    • 2013-01-13
    • 1970-01-01
    • 2011-12-01
    • 2018-07-26
    • 2020-12-30
    • 1970-01-01
    • 2019-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多