dev-resources.site
for different kinds of informations.
Fix: physical keyboard can't type in Flutter's Webview
Problem
We are using a webview for our app built with Flutter (version 2.2.3). The main part code like this:
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('Keyboard Test')),
body: WebView(
initialUrl: 'https://duckduckgo.com',
),
),
);
}
}
When our iOS device connects to a bluetooth physical keyboard and open the app, inside the input box, the keyboard doesn't work, can't type anything.
Solution
This seems a Flutter bug (view the discussion here), and it looks like it has been fixed in the master branch, but hasn't been released to stable. At the time of writing this, the latest Flutter stable version is 2.2.3, so the later version might fix this issue.
But if you want to fix it now w/o waiting for the new version release, here is a temporary solution:
Go to your project folder: "ios > Runner > AppDelegate.swift", then simply add these code to that file:
extension FlutterViewController {
open override func pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
super.pressesBegan(presses, with: event)
}
open override func pressesEnded(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
super.pressesEnded(presses, with: event)
}
open override func pressesCancelled(_ presses: Set<UIPress>, with event: UIPressesEvent?) {
super.pressesCancelled(presses, with: event)
}
}
Recompile your app, the problem should be fixed.
Reference
Featured ones: