简体   繁体   English

Flutter 键盘出现时溢出底部

[英]Flutter overflow bottom when keyboard appears

i got this error and i cant get why, in a new screen i got a simple form on top (start of the column), when i focus the textfield the keyboard appears and overflow the date select and the button, but i dont know why.我收到此错误,但我不明白为什么,在一个新屏幕中,我在顶部(列的开头)有一个简单的表单,当我聚焦文本字段时,键盘出现并溢出日期 select 和按钮,但我不知道为什么.

Here is the initial state whiout focus on the textfield这是最初的 state 不关注文本字段在此处输入图像描述

and here is when i focus the textfield.这是我关注文本字段的时候。 在此处输入图像描述

This is the widget i got to do this.这是我要做的小部件。

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

Yo can set to false the resizeToAvoidBottomInset in your Scaffold()你可以将Scaffold()中的resizeToAvoidBottomInset设置为 false

Like this像这样

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

Documentation reference: Scaffold - resizeToAvoidBottomInset文档参考: Scaffold - resizeToAvoidBottomInset

It's beginner level problem.是初级问题。 Don't know why most tutorial don't cover this problem before showing TextField Widget.不知道为什么大多数教程在显示 TextField Widget 之前没有涵盖这个问题。

Column widget is fixed and does not scroll.列小部件是固定的,不会滚动。 So change Column to ListView.所以将 Column 更改为 ListView。 And do nothing else.并且什么也不做。 The Widget will gain scroll feature and overflow problem will not happen anymore. Widget 将获得滚动功能,并且不会再发生溢出问题。

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

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