繁体   English   中英

Flutter 键盘出现时溢出底部

[英]Flutter overflow bottom when keyboard appears

我收到此错误,但我不明白为什么,在一个新屏幕中,我在顶部(列的开头)有一个简单的表单,当我聚焦文本字段时,键盘出现并溢出日期 select 和按钮,但我不知道为什么.

这是最初的 state 不关注文本字段在此处输入图像描述

这是我关注文本字段的时候。 在此处输入图像描述

这是我要做的小部件。

return Scaffold(
  body: SafeArea(
      child: Column(
    children: <Widget>[
      TopBarWidget(page: 'New Event', title: 'Nuevo Evento'),
      Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            TextField(
              onChanged: (value) {
                eDisplayName = value;
              },
              maxLength: 18,
              keyboardType: TextInputType.text,
              textCapitalization: TextCapitalization.sentences,
              cursorColor: Color(0xFFFC4A1A),
              decoration: InputDecoration(
                labelText: "Nombre del Evento",
                fillColor: Colors.white,
                border: new OutlineInputBorder(
                  borderRadius: new BorderRadius.circular(5.0),
                ),
              ),
            ),
            SizedBox(
              height: 16.0,
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                OutlineButton(
                  focusColor: Theme.of(context).primaryColor,
                  highlightedBorderColor: Theme.of(context).primaryColor,
                  borderSide: BorderSide(
                    color: Theme.of(context).primaryColor,
                  ),
                  textColor: Theme.of(context).primaryColor,
                  onPressed: () => _selectDate(context),
                  child: Text('Cambiar Fecha'),
                ),
                Text(
                  "${formatedDate(selectedDate.toLocal())}",
                  style: TextStyle(
                      fontSize: 18.0,
                      fontWeight: FontWeight.w500,
                      color: Theme.of(context).primaryColor),
                ),
                // Text("${selectedDate.toLocal()}"),
              ],
            ),
            SizedBox(
              height: 16.0,
            ),
            RaisedButton(
              disabledColor: Colors.grey[200],
              disabledTextColor: Colors.black,
              color: Theme.of(context).primaryColor,
              textColor: Colors.white,
              shape: RoundedRectangleBorder(
                  borderRadius: new BorderRadius.circular(10.0)),
              onPressed: eDisplayName.length == 0
                  ? null
                  : () {
                      // print(newEvent);
                      Navigator.pop(context);
                    },
              child: Text(
                'ACEPTAR',
                // style: TextStyle(fontSize: 20),
              ),
            ),
          ],
        ),
      ),
    ],
  )),
);

你可以将Scaffold()中的resizeToAvoidBottomInset设置为 false

像这样

return Scaffold(
  resizeToAvoidBottomInset: false,
  body: // ...
  // ...
)

文档参考: Scaffold - resizeToAvoidBottomInset

是初级问题。 不知道为什么大多数教程在显示 TextField Widget 之前没有涵盖这个问题。

列小部件是固定的,不会滚动。 所以将 Column 更改为 ListView。 并且什么也不做。 Widget 将获得滚动功能,并且不会再发生溢出问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM