【问题标题】:The layout breaks when the keypad pops up键盘弹出时布局中断
【发布时间】:2018-11-19 08:49:15
【问题描述】:

当我选择屏幕上的文本框时布局中断。如何使屏幕可以通过堆栈滚动

当用户开始在文本框中输入时,有什么方法可以将整个内容滚动到底部

代码:Gist

【问题讨论】:

  • 将内容放入SingleChildScrollView
  • 但是我需要两个部分中间的“OR”按钮和屏幕底部的提交按钮,所以使用了堆栈。请看代码
  • 然后将 Stack 放入滚动视图中。
  • 这不起作用,先生

标签: flutter flutter-layout


【解决方案1】:

您在错误的地方使用了堆栈。 您需要在上部(scanPortion)小部件中使用堆栈。 CircleAvatar 应该与 scanPortion 重叠并使溢出可见。这样,CircleAvatar 将被卡在 scanPortion 上并随之滚动。

从当前位置移除 CircleAvatar 并将 scanPortion 更改为以下内容:

var scanPortion = new Stack(
  children: <Widget>[
    new Container(
      height: MediaQuery.of(context).size.height / 2 - 40,
      width: MediaQuery.of(context).size.width,
      color: new Color(0xFF4A4A4C).withOpacity(0.5),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          qrCode,
          SizedBox(
            height: 10.0,
          ),
          new RaisedButton.icon(
            color: Colors.blueAccent,
            textColor: Colors.white,
            shape: new RoundedRectangleBorder(
                borderRadius: new BorderRadius.circular(30.0)),
            onPressed: () async {},
            icon: new Icon(
              Icons.camera_alt,
              color: Colors.white,
            ),
            label: Text('Scan'),
          )
        ],
      ),
    ),
    Positioned(
      top: (MediaQuery.of(context).size.height / 2 - 40.0) - 20.0,
      left: (MediaQuery.of(context).size.width) / 2 - 20.0,
      child: Center(
        child: CircleAvatar(
          backgroundColor: Colors.pink,
          child: Text('OR'),
          radius: 20.0,
        ),
      ),
    ),
  ],
  overflow: Overflow.visible,
);

稍后小心删除旧堆栈,因为它没有任何用处。

【讨论】:

  • 成功了,非常感谢。有没有什么办法可以将提交按钮放在没有堆栈的底部?
  • 是的,在列中使用灵活和按钮。将您的 scanPortion 和 manualEntryPortion 设置为 Flexible。 Column( Flexible( ListView( scanPortion manualEntryPortion ) ) Container( FlatButton() ) )
  • 完美,拯救了我的一天
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-25
  • 2012-12-17
相关资源
最近更新 更多