[英]Is there a way to autofocus keyboard in webview textinput field in flutter?
I am using InAppWebView to show the webpage in a flutter app.我正在使用InAppWebView在颤振应用程序中显示网页。 Here keyboard is shown only when I tap on the input field.
只有当我点击输入字段时,才会显示这里的键盘。 Is there a way that the keyboard is visible before tapping on the input field?
有没有办法在点击输入字段之前显示键盘? The keyboard should appear right after navigating to this screen.
导航到此屏幕后,键盘应立即出现。 Here is the code:
这是代码:
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
class WebViewScreen extends StatefulWidget {
const WebViewScreen({Key? key}) : super(key: key);
@override
State<WebViewScreen> createState() => _WebViewScreenState();
}
class _WebViewScreenState extends State<WebViewScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Center(
child: InAppWebView(
initialUrlRequest:
URLRequest(url: Uri.parse('https://www.google.com')),
onWebViewCreated: (InAppWebViewController controller) {
print('onWebViewCreated');
},
onProgressChanged:
(InAppWebViewController controller, int progress) {
print('onProgressChanged: $progress');
},
),
),
),
);
}
}
Using addUserScript
method gives method implementation error.使用
addUserScript
方法会导致方法实现错误。
And using webview_flutter
plugin, it works:并使用
webview_flutter
插件,它可以工作:
class WebViewPage extends StatelessWidget {
const WebViewPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return WebView(
javascriptMode: JavascriptMode.unrestricted,
initialUrl: "https://google.com",
onWebViewCreated: (webViewController) {
String jsStr = "window.addEventListener('load', (event) => {"
"let i = document.getElementsByTagName('input');"
"i[0].focus();"
"console.log('done');"
"});";
webViewController.runJavascript(jsStr);
},
);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.