当键盘出现在 Flutter 中时向上移动文本字段 [英] Move textfield up when keyboard appears in Flutter

查看:56
本文介绍了当键盘出现在 Flutter 中时向上移动文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让我的文本字段在键盘出现时向上显示.键盘在文本框的前面,所以我看不到我写的东西,我没有找到很多解决我的问题的方法或者不是很干净.

I want to make my textfield go up when the keyboard appears. The keyboard is in front of textfield so I can't see what I write, I didn't found many solution to my problem or there were not very clean.

Widget build(BuildContext context) {
return Scaffold(
  backgroundColor: Theme.of(context).backgroundColor,
  body: Padding(
    padding: const EdgeInsets.all(8.0),
    child: Column(
      children: <Widget>[
        conseil(text),
        Spacer(),
        InkWell(
          onTap: () => [
            pic.getImage().then((a) {
              setState(() {
                myimg = myimage;
              });
            })
          ],
          child: Container(
            decoration: BoxDecoration(
                border: Border.all(width: 2.0, color: mygreen),
                boxShadow: <BoxShadow>[
                  BoxShadow(
                      color: mygreen, blurRadius: 0, offset: Offset(7, 3))
                ],
                shape: BoxShape.circle),
            child: ClipOval(
              child: SizedBox(
                width: 140,
                height: 140,
                child: (myimg != null)
                    ? Image.file(myimg, fit: BoxFit.fill)
                    : Image(
                        image: AssetImage('assets/images/others/add.png'),
                        fit: BoxFit.fill,
                      ),
              ),
            ),
          ),
        ),
        (myimage == null)?
        Text("Choisir une photo"): SizedBox(height: 1),
        Spacer(),
        SizedBox(
          width: 250,
          child: TextField(
            textAlign: TextAlign.center,
            style: TextStyle(color: Colors.white),
            decoration: InputDecoration(
                enabledBorder: OutlineInputBorder(
                    borderSide:
                        BorderSide(color: Color(0xFF37cd41), width: 2)),
                hintText: 'TON PRENOM',
                hintStyle: TextStyle(color: Colors.white)),
            controller: name,
          ),
        ),
        Spacer(),
        button(mypink, 'CONTINUER', widget.admin, context, name),
        Spacer(),
      ],
    ),
  ),
);
}
}

推荐答案

尝试使用 SingleChildScrollViewConstrainedBox.

Scaffold(
  body: SingleChildScrollView(
    child: ConstrainedBox(
      constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height),
      child: yourWidget()

签出以下答案:https://stackoverflow.com/a/59783374/12709039

这篇关于当键盘出现在 Flutter 中时向上移动文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆