Flutter: Keyboard overflow with My Dialog

本小妞迷上赌 提交于 2020-01-24 12:43:05

问题


I'am trying to add TextField to a Dialog, but when the Keyboard appears, it gives an overflow.

My dialog Image

When the Keyboard shows up

Here How a part my code looks Like:

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,
    )

回答1:


You can simply use 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,
        ),
        ]
    )
    )
)



回答2:


Wrapping this code around a dialog fixed this issue for me:

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


来源:https://stackoverflow.com/questions/51498911/flutter-keyboard-overflow-with-my-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!