【问题标题】:Flutter: Keyboard overflow with My DialogFlutter:键盘溢出与我的对话框
【发布时间】:2018-07-24 12:41:46
【问题描述】:

我正在尝试将 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( child: new Column( children: [ Text()]....

标签: dart flutter flutter-layout


【解决方案1】:

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

resizeToAvoidBottomInset: false,

这一行在“return Scaffold”下 我在 page 上找到了这个解决方案

【讨论】:

  • 问题中没有提到return Scaffold。您能否详细说明您找到的包含所有必需详细信息的解决方案?
  • 这应该是最好的答案,
  • 唯一对我有用的解决方案,谢谢!
  • @68060 最近不累。几个月前它还在工作。
  • 为我工作谢谢。
【解决方案2】:

你可以简单地使用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,
        ),
        ]
    )
    )
)

【讨论】:

  • 这似乎无法解决。
【解决方案3】:
 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,
        ),
        ]
    )
    )
)

【讨论】:

    【解决方案4】:

    “溢出条纹”警告实际上是在对话框后面的屏幕上,因此对话框本身没有错误。

    只需尝试添加一个SingleChildScrollView() 包裹在屏幕后面的孩子周围! (我有同样的错误,这对我有用)

    【讨论】:

      【解决方案5】:

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

      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);
        }
      }
      

      【讨论】:

        猜你喜欢
        • 2021-04-07
        • 1970-01-01
        • 2019-08-14
        • 2021-12-06
        • 1970-01-01
        • 2021-03-28
        • 2012-04-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多