键盘隐藏的TextFormField-Flutter

时间:2020-01-11 11:41:01

标签: flutter dart flutter-layout

当重点放在TextFormField上时,键盘将隐藏在TextFormField上。我正在将SingleScrollview与Column小部件一起使用。下面我附上了带有编码的屏幕截图。请指导我解决此问题。

Scaffold(
  resizeToAvoidBottomInset: false,
  resizeToAvoidBottomPadding: false,
  key: _scaffoldKey,
  body: SingleChildScrollView(
  child: Padding(
    padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
    child: new Column(
      children: <Widget>[
        _tabText(),
        isSignin ? _loginContainer() : _signUpContainer(),
      ],
    ),),),);

enter image description here enter image description here

4 个答案:

答案 0 :(得分:1)

///将此行“ resizeToAvoidBottomInset:true”添加到您的脚手架中,并将主 滚动视图中的容器。

    @override
    Widget build(BuildContext context) {
   return Scaffold(
   resizeToAvoidBottomInset: true,
   key: _scaffoldKey,
   backgroundColor: Colors.white,
   body: SingleChildScrollView(    
      child: Container()
    ),
   );
  }

答案 1 :(得分:0)

您必须删除Scaffold的以下属性:

  resizeToAvoidBottomInset: false,
  resizeToAvoidBottomPadding: false,

如果删除它们,默认情况下resizeToAvoidBottomInset将是true

resizeToAvoidBottomInset property:

...如果在支架上方显示了屏幕键盘,则 机身可以调整大小以避免键盘重叠,从而防止 人体内部的小部件不会被键盘遮挡。

答案 2 :(得分:0)

在scaffold()小部件之后尝试SingleChildScrollView()小部件。在Scaffold()小部件之后用SingleChildScrollView()小部件包装所有小部件。

Widget build(BuildContext context) {
return Scaffold( 
  body: SingleChildScrollView(
    child: Form(
      key: formKey,
      child: Column(
        children: <Widget>[
          Container(
            child: Stack(
              children: <Widget>[
                Container(

答案 3 :(得分:0)

我尝试使用动画来避免这种情况:

ScrollController _scrollController;                                 //<==  

class SignUpPage extends StatefulWidget {
  static String tag = 'SignUpPage';
  @override
  _SignUpPageState createState() => _SignUpPageState();
}

class _SignUpPageState extends State<SignUpPage> {

//Implementing scrollController by detecting keyboard               //<==
  bool scrolled = false;
  _scrollListener() {
    if (!scrolled && MediaQuery.of(context).viewInsets.bottom != 0) {
      _scrollController.animateTo(
        _scrollController.position.maxScrollExtent,
        duration: Duration(milliseconds: 100),
        curve: Curves.easeOut,
      );
      scrolled = true;
    }
    if (MediaQuery.of(context).viewInsets.bottom == 0) {
      scrolled = false;
    }
  }

  @override
  void initState() {
    _scrollController = ScrollController();
    _scrollController.addListener(_scrollListener);
    super.initState();
  }