弹出键盘时,TextField被隐藏

时间:2019-01-14 05:38:20

标签: android ios dart flutter

import 'package:e_expense/home.dart';
import 'package:flutter/material.dart';

class SignUpPage extends StatefulWidget {
 @override
  _SignUpState createState() => _SignUpState();
 }

class _SignUpState extends State<SignUpPage> {
 @override
 Widget build(BuildContext context) {
   return Scaffold(
     resizeToAvoidBottomPadding: false,
     appBar: AppBar(
      iconTheme: IconThemeData(
        color: Colors.green,
      ),
      centerTitle: true,
      title: Text(
        "Welcome to E-Expense",
        style: TextStyle(
            fontWeight: FontWeight.bold,
            fontFamily: 'Montserrat',
            color: Colors.green),
      ),
      elevation: 0.0,
      backgroundColor: Color(0x00000000).withOpacity(0),
    ),
    body: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        Flexible(
          fit: FlexFit.loose,
          child: Container(
            child: Stack(
              children: <Widget>[
                Container(
                  padding: EdgeInsets.fromLTRB(15.0, 50.0, 0.0, 0.0),
                  child: Text(
                    "Signup",
                    style: TextStyle(
                      fontSize: 80.0,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                ),
                Container(
                  padding: EdgeInsets.fromLTRB(270.0, 50.0, 0.0, 0.0),
                  child: Text(
                    ".",
                    style: TextStyle(
                      color: Colors.green,
                      fontSize: 80.0,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                )
              ],
            ),
          ),
        ),
        Container(
          padding: EdgeInsets.only(top: 35.0, left: 20.0, right: 20.0),
          child: Column(
            children: <Widget>[
              TextField(
                decoration: InputDecoration(
                  labelText: 'USER NAME',
                  labelStyle: TextStyle(
                    fontFamily: 'Montserrat',
                    fontWeight: FontWeight.bold,
                    color: Colors.grey,
                  ),
                  focusedBorder: UnderlineInputBorder(
                    borderSide: BorderSide(
                      color: Colors.green,
                    ),
                  ),
                ),
              ),
              SizedBox(height: 10.0),
              TextField(
                decoration: InputDecoration(
                  labelText: 'EMAIL',
                  labelStyle: TextStyle(
                    fontFamily: 'Montserrat',
                    fontWeight: FontWeight.bold,
                    color: Colors.grey,
                  ),
                  focusedBorder: UnderlineInputBorder(
                    borderSide: BorderSide(
                      color: Colors.green,
                    ),
                  ),
                ),
              ),
              SizedBox(height: 10.0),
              TextField(
                decoration: InputDecoration(
                  labelText: 'PASSWORD',
                  labelStyle: TextStyle(
                    fontFamily: 'Montserrat',
                    fontWeight: FontWeight.bold,
                    color: Colors.grey,
                  ),
                  focusedBorder: UnderlineInputBorder(
                    borderSide: BorderSide(
                      color: Colors.green,
                    ),
                  ),
                ),
              ),
              SizedBox(height: 10.0),
              TextField(
                decoration: InputDecoration(
                  labelText: 'REPEAT PASSWORD',
                  labelStyle: TextStyle(
                    fontFamily: 'Montserrat',
                    fontWeight: FontWeight.bold,
                    color: Colors.grey,
                  ),
                  focusedBorder: UnderlineInputBorder(
                    borderSide: BorderSide(
                      color: Colors.green,
                    ),
                  ),
                ),
              ),
              SizedBox(height: 40.0),
              ButtonBar(
                alignment: MainAxisAlignment.end,
                children: <Widget>[
                  FlatButton(
                      onPressed: () {},
                      child: Text(
                        'CANCEL',
                        style: TextStyle(
                          fontFamily: 'Montserrat',
                          fontWeight: FontWeight.normal,
                          color: Colors.black,
                        ),
                      )),
                  RaisedButton(
                    onPressed: () {
                      Navigator.of(context).push(MaterialPageRoute(
                          builder: (BuildContext context) => HomePage(),
                          fullscreenDialog: false));
                    },
                    color: Colors.green,
                    child: Text(
                      'SIGNUP',
                      style: TextStyle(
                        fontFamily: 'Montserrat',
                      fontSize: 15.0),

                    ),
                    textColor: Colors.white,
                  )
                ],
              )
            ],
          ),
        ),
      ],
    ));
 }
}

您好,这是我的第一个Flutter应用。我一直在尝试创建一个带有少量文本字段的注册页面。一切看起来都不错,但是每当我单击任何文本框软键盘上的显示并隐藏归档的文本时(请查看所附图像) keyboard hiding the textfield textfields without keyboard

3 个答案:

答案 0 :(得分:1)

请尝试用包含TextField的包含这些SingleChildScrollView widget

答案 1 :(得分:1)

一些更改:

  • 设置resizeToAvoidBottomPadding为真

  • 删除Flexible小部件

  • 将您的第一个Column包裹在SingleChildScrollView

     @override
      Widget build(BuildContext context) {
        return Scaffold(
            resizeToAvoidBottomPadding: true,
            appBar: AppBar(
              iconTheme: IconThemeData(
                color: Colors.green,
              ),
              centerTitle: true,
              title: Text(
                "Welcome to E-Expense",
                style: TextStyle(
                    fontWeight: FontWeight.bold,
                    fontFamily: 'Montserrat',
                    color: Colors.green),
              ),
              elevation: 0.0,
              backgroundColor: Color(0x00000000).withOpacity(0),
            ),
            body: SingleChildScrollView(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Container(
                    child: Stack(
                      children: <Widget>[
                        Container(
                          padding: EdgeInsets.fromLTRB(15.0, 50.0, 0.0, 0.0),
                          child: Text(
                            "Signup",
                            style: TextStyle(
                              fontSize: 80.0,
                              fontWeight: FontWeight.bold,
                            ),
                          ),
                        ),
                        Container(
                          padding: EdgeInsets.fromLTRB(270.0, 50.0, 0.0, 0.0),
                          child: Text(
                            ".",
                            style: TextStyle(
                              color: Colors.green,
                              fontSize: 80.0,
                              fontWeight: FontWeight.bold,
                            ),
                          ),
                        )
                      ],
                    ),
                  ),
                  Container(
                    padding: EdgeInsets.only(top: 35.0, left: 20.0, right: 20.0),
                    child: SingleChildScrollView(
                      child: Column(
                        children: <Widget>[
                          TextField(
                            decoration: InputDecoration(
                              labelText: 'USER NAME',
                              labelStyle: TextStyle(
                                fontFamily: 'Montserrat',
                                fontWeight: FontWeight.bold,
                                color: Colors.grey,
                              ),
                              focusedBorder: UnderlineInputBorder(
                                borderSide: BorderSide(
                                  color: Colors.green,
                                ),
                              ),
                            ),
                          ),
                          SizedBox(height: 10.0),
                          TextField(
                            decoration: InputDecoration(
                              labelText: 'EMAIL',
                              labelStyle: TextStyle(
                                fontFamily: 'Montserrat',
                                fontWeight: FontWeight.bold,
                                color: Colors.grey,
                              ),
                              focusedBorder: UnderlineInputBorder(
                                borderSide: BorderSide(
                                  color: Colors.green,
                                ),
                              ),
                            ),
                          ),
                          SizedBox(height: 10.0),
                          TextField(
                            decoration: InputDecoration(
                              labelText: 'PASSWORD',
                              labelStyle: TextStyle(
                                fontFamily: 'Montserrat',
                                fontWeight: FontWeight.bold,
                                color: Colors.grey,
                              ),
                              focusedBorder: UnderlineInputBorder(
                                borderSide: BorderSide(
                                  color: Colors.green,
                                ),
                              ),
                            ),
                          ),
                          SizedBox(height: 10.0),
                          TextField(
                            decoration: InputDecoration(
                              labelText: 'REPEAT PASSWORD',
                              labelStyle: TextStyle(
                                fontFamily: 'Montserrat',
                                fontWeight: FontWeight.bold,
                                color: Colors.grey,
                              ),
                              focusedBorder: UnderlineInputBorder(
                                borderSide: BorderSide(
                                  color: Colors.green,
                                ),
                              ),
                            ),
                          ),
                          SizedBox(height: 40.0),
                          ButtonBar(
                            alignment: MainAxisAlignment.end,
                            children: <Widget>[
                              FlatButton(
                                  onPressed: () {},
                                  child: Text(
                                    'CANCEL',
                                    style: TextStyle(
                                      fontFamily: 'Montserrat',
                                      fontWeight: FontWeight.normal,
                                      color: Colors.black,
                                    ),
                                  )),
                              RaisedButton(
                                onPressed: () {
                                  Navigator.of(context).push(MaterialPageRoute(
                                      builder: (BuildContext context) => null,
                                      fullscreenDialog: false));
                                },
                                color: Colors.green,
                                child: Text(
                                  'SIGNUP',
                                  style: TextStyle(
                                      fontFamily: 'Montserrat', fontSize: 15.0),
                                ),
                                textColor: Colors.white,
                              )
                            ],
                          )
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ));
      }
    

答案 2 :(得分:1)

请使用

android:windowSoftInputMode =“ adjustPan” 在forAndroidManifest.xml中进行活动SignUpPage