Flutter:我的对话框键盘溢出

Flutter: Keyboard overflow with My Dialog

我正在尝试将 TextField 添加到对话框,但是当键盘出现时,它会溢出。

我的对话图片

键盘出现时

这是我的代码的一部分:

AlertDialog(
    content: new ListView(
      shrinkWrap: true,
  children: <Widget>[
    Text(
      "How Would You Rate Our App?",
      style: TextStyle(fontSize: 16.0, fontWeight: FontWeight.bold),
      textAlign: TextAlign.center,
    )

您可以简单地使用 SingleChildScrollView:

 AlertDialog(
        content: SingleChildScrollView(
          scrollDirection: Axis.vertical,
        child: Column(
          children: <Widget>[
            Text(
              "How Would You Rate Our App?",
              style: TextStyle(fontSize: 16.0, fontWeight: FontWeight.bold),
              textAlign: TextAlign.center,
        ),
        ]
    )
    )
)

将此代码包装在一个对话框中为我解决了这个问题:

class _SystemPadding extends StatelessWidget {
  final Widget child;

  _SystemPadding({Key key, this.child}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var mediaQuery = MediaQuery.of(context);
    return new AnimatedContainer(
        padding: const EdgeInsets.only(bottom: mediaQuery.viewInsets.bottom),
        duration: const Duration(milliseconds: 300),
        child: child);
  }
}

"overflow stripes" 警报实际上在对话框后面的屏幕上,因此对话框本身没有错误。

试试在后面的屏幕 child 周围添加一个 SingleChildScrollView() 环绕! (我有同样的错误,这对我有用)

 AlertDialog(
        content: SingleChildScrollView(
        child: Column(
          children: <Widget>[
            Text(
              "How Would You Rate Our App?",
              style: TextStyle(fontSize: 16.0, fontWeight: FontWeight.bold),
              textAlign: TextAlign.center,
        ),
        ]
    )
    )
)

问题出在对话框后面的屏幕上。我遇到了同样的问题,但上面的解决方案没有一个适用于我的代码,所以我使用了这个代码:

resizeToAvoidBottomInset: false,

这一行在“return脚手架”下 我在 page

上找到了这个解决方案