【问题标题】:When typing on textfield, keyboard is block the view on flutter在文本字段上键入时,键盘会阻止颤动的视图
【发布时间】:2020-02-27 21:09:50
【问题描述】:

我在屏幕底部有一个文本框,当我尝试点击它时,它被键盘挡住了。

在按下文本字段之前

按下文本字段后

这是代码

import 'package:flutter/material.dart';
import 'package:survey/content/7scontent.dart';
import 'package:survey/content/surveycon.dart';
import 'package:survey/widgets/animations.dart';
import '../widgets/buttonstyle.dart';
import 'package:survey/widgets/widgetlist.dart';

class sevens extends StatelessWidget {
  final listoftitle = [
    "I & II Sweep & Standardize", "III Santize", "IV Save", "V Safety and VI Security", "VII Self Discipline",
  ];

  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        resizeToAvoidBottomPadding: true,
        resizeToAvoidBottomInset: false,
        body: Center(
            child: Padding(
              padding: EdgeInsets.all(5),
              child: Column(
                children: <Widget>[
                  Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      SizedBox(height: 30),
                      Center(
                        child: SizedBox(
                          height: 50,
                          width: 300,
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: <Widget>[
                              Image.asset(imgtitle1,width: 100,height: 70,),
                              SizedBox(width: 50,),
                              Image.asset(imgtitle2,width: 100,height: 70,),
                            ],
                          ),
                        ),
                      ),
                      SizedBox(
                        height: 30,
                      ),
                      Text(
                        'COMMITMENT TO CARE (INTENSIFIED 7S)',
                        maxLines: 2,
                        textAlign: TextAlign.center,
                        overflow: TextOverflow.ellipsis,
                        style: TextStyle(
                            color: Colors.orangeAccent,
                            fontWeight: FontWeight.bold,
                            fontSize: 25.0),
                      ),
                      SizedBox(
                        height: 20,
                      ),
                      Container(
                        padding: const EdgeInsets.symmetric(horizontal: 1.0, vertical: 2.0),
                        width: MediaQuery.of(context).size.width,
                        height: MediaQuery.of(context).size.width/ 1.2,
                        child: ListView.builder(
                          itemCount: listoftitle.length,
                          physics: NeverScrollableScrollPhysics(),
                          itemBuilder: (context, index){
                            return ListTile(
                              title: Text(listoftitle[index],textAlign: TextAlign.center,),
                            );
                          },
                        ),
                      ),
                      Container(
                        width: 300,
                        child: TextFormField(
                          decoration: InputDecoration(
                              labelText: 'ENTER YOUR EMPLOYEE ID HERE!',
                            border: OutlineInputBorder(borderRadius: BorderRadius.circular(10.0)),
                          ),
                        ),
                      ),
                      SizedBox(height: 30),
                      Center(
                        child: InkWell(
                          onTap: (){
                            Navigator.push(context, SlideRightRoute(page: sevenscontent()));
                          },
                          child: roundedRectButton("PROCEED", signInGradients),),
                      )
                    ],
                  ),
                ],
              ),
            )
        ),
      ),
    );
  }
}

谁能帮忙?我尝试使用SingleScrollView 进行一些试验,但没有成功。

【问题讨论】:

  • 类应以大写字母Seven
  • 将您的中心小部件包装在 SingleChildScrollView 小部件中。

标签: flutter keyboard textfield singlechildscrollview


【解决方案1】:

我建议给this a lookThis plugin 也可用于检查键盘是否打开。

【讨论】:

    【解决方案2】:

    SingleScrollView 或任何滚动视图都是解决此问题的好方法。

    首先,我们希望Scaffold 在键盘出现时调整大小,这样我们就不会隐藏任何东西。为此,您应该删除:

    resizeToAvoidBottomPadding: true,(已弃用,不使用) resizeToAvoidBottomInset: false, (默认: true)

    然后在CenterPadding 之间添加一个SingleScrollView,这样就可以了

    【讨论】:

      【解决方案3】:

      有点晚了,但希望这仍然可以帮助你:

      Scaffold(
        body: LayoutBuilder(
          builder: (context, constraint) {
            child: SingleChildScrollView(
              child: ConstrainedBox(
                constraints: BoxConstraints(minHeight: constraint.maxHeight),
                child: IntrinsicHeight(
                  child: Column(
                    // your content (Text, Container, TextField, ...)
                  )
                )
              )
            )
          }
        )
      )
      

      这样,当你专注于 TextField 并显示键盘时,TextField 将滚动到键盘上方的可见位置。

      【讨论】:

        猜你喜欢
        • 2021-06-19
        • 2015-07-20
        • 2021-05-07
        • 2019-10-19
        • 1970-01-01
        • 2021-04-03
        • 1970-01-01
        • 2020-09-17
        • 1970-01-01
        相关资源
        最近更新 更多