1

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

在按下文本字段之前

                                           

按下文本字段后

                                           

这是代码

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但没有成功。

4

3 回答 3

0

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

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 将滚动到键盘上方的可见位置。

于 2020-11-04T08:17:37.513 回答
0

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

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

resizeToAvoidBottomPadding: true,(不推荐使用,不使用) resizeToAvoidBottomInset: false,(默认值:true)

然后添加一个SingleScrollView介于Center和之间Padding应该可以解决问题

于 2020-02-27T23:30:18.540 回答
0

我建议看看这个这个插件对于检查键盘是否打开也很有用。

于 2020-02-27T23:27:44.837 回答