首页 > 解决方案 > 使用手机键盘时颤动,文本框被隐藏

问题描述

我的电话键盘出现问题,妨碍了用户必须写入的文本框,因为用户看不到他在写什么,这就是它的样子

这是没有键盘的屏幕 没有键盘的手机屏幕

这是带键盘的屏幕

带键盘的电话屏幕

这是我当前的文本字段代码

TextFormField(
                      initialValue: '',
                      onChanged: (text) {
                        messageEntered = text;
                      },
                      style: TextStyle(color: Colors.white),
                      decoration: InputDecoration(
                          labelText:
                              Translations.of(context).trans('message'),
                          fillColor: Colors.white,
                          labelStyle: TextStyle(color: Colors.white)),
                    ),

有没有办法防止这种情况发生?感谢您的时间

编辑:这是我的页面代码,脚手架已经包装

return showDialog(
    barrierDismissible: false,
    context: context,
    builder: (BuildContext context) {
      return StatefulBuilder(builder: (context, setState) {
        return WillPopScope(
            onWillPop: () {
              return Future.value(true);
            },
            child: Scaffold(
                  resizeToAvoidBottomPadding: false, 
              body: Container(
                color: Colors.red,
                padding: const EdgeInsets.all(16.0),
                width: double.infinity,
                height: double.infinity,
                child: Column(
                  children: <Widget>[
                    Container(height: 30),
                    new Text(
                      Translations.of(context).trans('sendmessage'),
                      style: TextStyle(color: Colors.white),
                    ),
                    Container(
                      height: 30,
                    ),
                    DropdownButton(
                      focusColor: Colors.white,
                      hint: new Text(
                        Translations.of(context).trans('sendto'),
                        style: TextStyle(color: Colors.white),
                      ),
                      isExpanded: true,
                      onChanged: (value) {
                        setState(() => selected = value);
                        setState(() => toEntered = selected);
                      },
                      value: selected,
                      items: workers.map((worker) {
                        return DropdownMenuItem(
                          child: new Text(worker.vNome),
                          value: worker.vCodigo,
                        );
                      }).toList(),
                    ),
                    Container(
                      height: 30,
                    ),
                    TextFormField(
                        initialValue: date,
                        onChanged: (text) {
                          dateEntered = text;
                        },
                        style: TextStyle(color: Colors.white),
                        decoration: InputDecoration(
                            labelText:
                                Translations.of(context).trans('date'),
                            fillColor: Colors.white,
                            labelStyle: TextStyle(color: Colors.white))),
                    Container(
                      height: 30,
                    ),
                    TextFormField(
                        initialValue: hour,
                        onChanged: (text) {
                          hourEntered = text;
                        },
                        style: TextStyle(color: Colors.white),
                        decoration: InputDecoration(
                            labelText:
                                Translations.of(context).trans('hour'),
                            fillColor: Colors.white,
                            labelStyle: TextStyle(color: Colors.white))),
                    Container(
                      height: 30,
                    ),
                    TextFormField(
                      initialValue: '',
                      onChanged: (text) {
                        messageEntered = text;
                      },
                      style: TextStyle(color: Colors.white),
                      decoration: InputDecoration(
                          labelText:
                              Translations.of(context).trans('message'),
                          fillColor: Colors.white,
                          labelStyle: TextStyle(color: Colors.white)),
                    ),
                    Spacer(),
                    Row(
                      children: <Widget>[
                        FlatButton(
                            textColor: Colors.white,
                            color: Colors.red[800],
                            child: Text(Translations.of(context)
                                .trans('sendmessage')),
                            onPressed: () {
                              sendMessage();
                            }),
                        Spacer(),
                        FlatButton(
                            textColor: Colors.white,
                            color: Colors.red[800],
                            child: Text(Translations.of(context)
                                .trans('closealert')),
                            onPressed: () {
                              setState(() => selected = null);
                              Navigator.of(context).pop();
                            }),
                      ],
                    ),
                  ],
                ),
              ),
            ));
      });
    });

标签: fluttertextfieldandroid-softkeyboard

解决方案


尝试这个,

return showDialog(
  barrierDismissible: false,
  context: context,
  builder: (BuildContext context) {
    return StatefulBuilder(
      builder: (context, setState) {
        return WillPopScope(
          onWillPop: () {
            return Future.value(true);
          },
          child: Scaffold(
            body: LayoutBuilder(
              builder: (context, constraint) {
                return SingleChildScrollView(
                  child: ConstrainedBox(
                    constraints: BoxConstraints(
                      minHeight: constraint.maxHeight,
                    ),
                    child: IntrinsicHeight(
                      child: Container(
                        color: Colors.red,
                        padding: const EdgeInsets.all(16.0),
                        child: Column(
                          children: <Widget>[
                            Container(height: 30),
                            new Text(
                              Translations.of(context).trans('sendmessage'),
                              style: TextStyle(color: Colors.white),
                            ),
                            Container(
                              height: 30,
                            ),
                            DropdownButton(
                              focusColor: Colors.white,
                              hint: new Text(
                                Translations.of(context).trans('sendto'),
                                style: TextStyle(color: Colors.white),
                              ),
                              isExpanded: true,
                              onChanged: (value) {
                                setState(() => selected = value);
                                setState(() => toEntered = selected);
                              },
                              value: selected,
                              items: workers.map((worker) {
                                return DropdownMenuItem(
                                  child: new Text(worker.vNome),
                                  value: worker.vCodigo,
                                );
                              }).toList(),
                            ),
                            Container(
                              height: 30,
                            ),
                            TextFormField(
                              initialValue: date,
                              onChanged: (text) {
                                dateEntered = text;
                              },
                              style: TextStyle(color: Colors.white),
                              decoration: InputDecoration(
                                labelText:
                                    Translations.of(context).trans('date'),
                                fillColor: Colors.white,
                                labelStyle: TextStyle(color: Colors.white),
                              ),
                            ),
                            Container(
                              height: 30,
                            ),
                            TextFormField(
                              initialValue: hour,
                              onChanged: (text) {
                                hourEntered = text;
                              },
                              style: TextStyle(color: Colors.white),
                              decoration: InputDecoration(
                                labelText:
                                    Translations.of(context).trans('hour'),
                                fillColor: Colors.white,
                                labelStyle: TextStyle(color: Colors.white),
                              ),
                            ),
                            Container(
                              height: 30,
                            ),
                            TextFormField(
                              initialValue: '',
                              onChanged: (text) {
                                messageEntered = text;
                              },
                              style: TextStyle(color: Colors.white),
                              decoration: InputDecoration(
                                labelText: Translations.of(context)
                                    .trans('message'),
                                fillColor: Colors.white,
                                labelStyle: TextStyle(color: Colors.white),
                              ),
                            ),
                            Spacer(),
                            Row(
                              children: <Widget>[
                                FlatButton(
                                  textColor: Colors.white,
                                  color: Colors.red[800],
                                  child: Text(Translations.of(context)
                                      .trans('sendmessage')),
                                  onPressed: () {
                                    sendMessage();
                                  },
                                ),
                                Spacer(),
                                FlatButton(
                                  textColor: Colors.white,
                                  color: Colors.red[800],
                                  child: Text(
                                    Translations.of(context)
                                        .trans('closealert'),
                                  ),
                                  onPressed: () {
                                    setState(() => selected = null);
                                    Navigator.of(context).pop();
                                  },
                                ),
                              ],
                            ),
                          ],
                        ),
                      ),
                    ),
                  ),
                );
              },
            ),
          ),
        );
      },
    );
  },
);

推荐阅读