flutter - 显示alertDialog时 flutter 键盘被关闭

标签 flutter dart

我的Flutter应用程序中有一个文本字段,用户可以在其中输入他们的姓名。他们可以按“提交”。但是当名称太短时,我会显示一个对话框。

问题:当显示对话框时,键盘自动关闭,并且警报对话框从上方(当键盘仍处于 Activity 状态时)跳转到下方(当键盘不再处于 Activity 状态时,半秒后)。

                        showDialog(
                            context: context,
                            builder: (_) => new AlertDialog(
                                  title: Text("Error"),
                                  content:
                                      Text("Name too short"),
                                ));

显示AlertDialog时是否可以保持键盘处于 Activity 状态?

谢谢!

最佳答案

我不相信有一种方法可以做您想做的事,但我已经弄清楚了hack尝试一下,看看您的想法

Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            TextFormField(
              onFieldSubmitted: (String value) async {
                if (value.length < 3) {
                  return await showDialog(
                    context: context,
                    builder: (_) => AlertDialog(
                      title: Text("Error"),
                      content: Column(
                        mainAxisSize: MainAxisSize.min,
                        children: <Widget>[
                          AbsorbPointer(
                            child: TextFormField(
                              cursorColor: Colors.white,
                              decoration: InputDecoration(
                                border: InputBorder.none,
                                hintText: " Name too short",
                                hintStyle: TextStyle(color: Colors.black),
                              ),
                              autofocus: true,
                            ),
                          ),
                        ],
                      ),
                    ),
                  );
                }
              },
            )
          ],
        ),
      ),

关于flutter - 显示alertDialog时 flutter 键盘被关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61292620/

相关文章:

android - 地理编码器 getFromLocation 失败

Flutter 小部件状态未更新 - 抛出 'Looking up a deactivated widget' 的祖先不安全'

flutter - 我无法使用 stdout.write 打印到 VSCode 的控制台

android - 在Dart中从云中解析嵌套的JSON但出现类型错误

android - Flutter 找不到预装的 Android SDK

java - 在 Dart 和 Java 之间共享类型

Flutter - 如何为切换选项卡时移动的 TabBar 创建自定义指示器 - 我有一个 DartPad 示例

flutter - 解析图像编解码器时抛出 ImageCodecException

firebase - 预期为 'Map<String, dynamic>' 类型的值,但得到了 'Null' 类型的值

forms - Dart不允许我使用POST方法