TextFormField上消失点击

问题描述 投票:0回答:3

我有形式抓住从用户信息。但是,当我敲击TextFormField和键盘显示消失。

https://youtu.be/UhVL2hqWOlQ

这里是我的代码:

class _AddInfoState extends State<AddInfo>{

  static final GlobalKey<FormState> _key = new GlobalKey();
  bool _validate = false;
  String strTitle;
  File fileImage;

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      body:new Container(
        child: new Form(
          key: _key,
          autovalidate: _validate,
          child: formUI(),
        ),
      ),
    );
  }

  Widget formUI(){
    return new ListView(
      children: <Widget>[
        //Title Field
        new Container(
          padding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 0.0),
          child:new TextFormField(
            style: styleTextField,
            keyboardType: TextInputType.text,
            autofocus: true,
            maxLength: 45,
            decoration: InputDecoration(
                hintText: 'Enter Title',
                prefixIcon: Icon(
                  Icons.title,
                  size: 30.0,
                  color: blueColor,
                )
            ),
            validator: validateTitle,
            onSaved: (String val) {
              strTitle = val;
            },
          ),
        ),                
      ],
      physics: new ClampingScrollPhysics(),
    );
  }
dart flutter flutter-layout
3个回答
0
投票

从视频我的理解,既然你已经用你的表单内滚动ListView,列表向上滚动,一旦键盘出现,因此它消失。

尝试在你的脚手架设置resizeToAvoidBottomPadding: false。这将使键盘出现重叠,不会向上推内容。

例:

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      resizeToAvoidBottomPadding: false,
      body:new Container(
        child: new Form(
          key: _key,
          autovalidate: _validate,
          child: formUI(),
        ),
      ),
    );
  }

让我知道如果这有助于!


0
投票

总结其必须在ContainerTextFormFieldSizedBox

                new Form(
                autovalidate: false,
                key: _formKey,
                child: new Container(
                  height: orientation == Orientation.portrait ?  MediaQuery.of(context).size.height :  MediaQuery.of(context).size.width/1.2 ,
                  padding: EdgeInsets.only(left: 10.0, right: 10.0),
                  child:  new Column(
                    //mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: <Widget>[
                       Container(
                        padding: EdgeInsets.only(top: 20.0),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                          children: <Widget>[
                            new SizedBox(
                            width: MediaQuery.of(context).size.width,
                            height: 100.0,
                            child: new Container(
                            padding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 0.0),
                             child:new TextFormField(
                             style: styleTextField,
                             keyboardType: TextInputType.text,
                             autofocus: true,
                             maxLength: 45,
                             decoration: InputDecoration(
                             hintText: 'Enter Title',
                             prefixIcon: Icon(
                             Icons.title,
                             size: 30.0,
                             color: blueColor,
                           )
                         ),
                         validator: validateTitle,
                         onSaved: (String val) {
                           strTitle = val;
                         },
                       ),
                     ),          
                   )

                           ]
                         )
                       )
                     ]
                   )
                 )
               )

0
投票

设置resizeToAvoidBottomPadding: false然后Column更改为ListView

© www.soinside.com 2019 - 2024. All rights reserved.