Flutter - Android 12 设备上键盘未显示

9

安卓 12 设备上键盘无法显示,出现覆盖层表明键盘已打开但没有显示。在旧版安卓系统中正常工作。

键盘在其他应用程序中工作正常,并且在 Android 12 以外的模拟器中也可以正常工作。已尝试使用物理设备,像 Pixel 安卓 12 版本也遇到了相同的问题。

flutter doctor 代码:

flutter doctor -v
[✓] Flutter (Channel stable, 2.2.3, on macOS 11.4 20F71 darwin-x64, locale en-IN)
    • Flutter version 2.2.3 at /Users/uable/Downloads/flutter
    • Framework revision f4abaa0735 (4 months ago), 2021-07-01 12:46:11 -0700
    • Engine revision 241c87ad80
    • Dart version 2.13.4

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/uable/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • ANDROID_HOME = /Users/uable/Library/Android/sdk
    • ANDROID_SDK_ROOT = /Users/uable/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS
    ✗ Xcode installation is incomplete; a full installation is necessary for iOS development.
      Download at: https://developer.apple.com/xcode/download/
      Or install Xcode via the App Store.
      Once installed, run:
        sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
        sudo xcodebuild -runFirstLaunch
    • CocoaPods version 1.10.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] Connected device (2 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 12 (API 31) (emulator)
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 95.0.4638.54

! Doctor found issues in 1 category.

以下是一个简单文本字段和键盘的图像,我尝试了修改所有文本字段的属性,但还是无法解决问题。这是一款现有应用程序,所以我尝试测试现有的文本字段,即使在这些字段中也显示相同的行为。

安卓Gradle设置

    minSdkVersion 24
    targetSdkVersion 30

enter image description here


2
嗨,Sharan,你修复了这个错误吗?我也遇到了同样的问题! - Abdel
2
我有同样的问题,刚刚尝试添加了android:hardwareAccelerated="true",但似乎没有任何改变。在我的情况下,是Flutter webview没有触发键盘显示。 - theLastNightTrain
1
遇到了与@theLastNightTrain完全相同的问题:标志android:hardwareAccelerated="true"已正确设置,但我的Webview不显示键盘...(仅在Android 12上,在物理设备上...) - Didier Prophete
2
在一个物理的 Android 12 设备上,在 WebView 中,对我有用的解决方法是使用 (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();。基本上,将 WebView 放入混合组合模式(请参见 https://pub.dev/packages/webview_flutter)。 - Didier Prophete
当我在WebViews中使用混合组合时,我会遇到这个问题。不确定我做了什么其他人没有做的事情来使它工作。所以在虚拟机上,在Android 12中我不能使用键盘,而在混合模式下应用程序会冻结。https://github.com/flutter/flutter/issues/86157 - parkgrrr
显示剩余2条评论
3个回答

1

进入安卓模拟器 --> 工具 --> AVD管理器--> 选择你正在运行的设备并 wipedata,然后再次运行。

如果这样不起作用,请选择另一个设备并尝试。

我不确定,可能是在 模拟器 中出现了问题。


1
键盘在其他应用程序中工作正常,也在模拟器上与 Android 12 版本不同的版本中正常工作。尝试使用物理设备 Pixel 并且在 Android 12 上遇到相同的问题。 - Sharan Singh
@SharanSingh 你找到解决方案了吗? - Shahbaz Hashmi
@SharanSingh 有任何更新吗?我也遇到了同样的问题。 - IamVariable

0
作为Flutter WebView的官方文档,放置。
if (Platform.isAndroid) WebView.platform = AndroidWebView();

在你的 Main.dart 文件中

输入图像描述


0

在此输入图像描述 我认为这是一个bug,因为模拟器与系统UI出现了错误,您可以清除模拟器数据,然后再次运行。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接