Home > Enterprise >  Flutter:(TextFormField)Problem when opening the keyboard and start typing
Flutter:(TextFormField)Problem when opening the keyboard and start typing

Time:03-03

When I open the keyboard to start typing, the problem appears that there is too much space [1]: https://i.stack.imgur.com/Nk4l6.png [2]: https://i.stack.imgur.com/12jNe.png the code:

import 'package:awesome_dialog/awesome_dialog.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';

class SignUpScreen extends StatelessWidget {
@override

var Email, Pass;
var txt;
GlobalKey<FormState> formstate = new GlobalKey<FormState>();


  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        toolbarHeight: 0,
        leading: Container(),
        backgroundColor: Color(0xFF03045E),
      ),
      body: Container(
        width: double.infinity,
        decoration: BoxDecoration(
          gradient: LinearGradient(
              begin: Alignment.topCenter,
              end: Alignment.bottomCenter,
              colors: [Color(0xFF03045E),Color(0xFF1F21D5),]
          ),
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Expanded(child: Column(
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: [
                    Container(
                      width: 45,
                      height: 45,
                      margin: EdgeInsets.only(top: 70,right: 35),
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(10),
                        color: Color(0xff383989),
                      ),
                      child: FlatButton(
                          onPressed: (){
                            Get.back();
                          },
                          child: Image(
                            image: AssetImage('assets/images/cancel-icon.png'),
                            color: Colors.white,
                            width: double.infinity,
                          ),
                      ),
                    ),
                  ],
                ),
                Container(
                  margin: EdgeInsets.symmetric(horizontal: 35),
                  child: Column(
                    children: [
                      Container(
                        margin: EdgeInsets.only(bottom: 40),
                        child: Row(
                          children: [
                            Text('Create\n Account',style: TextStyle(
                                color: Colors.white,
                                fontSize: 30
                            ),),
                          ],
                        ),
                      ),
                      Row(
                        children: [
                          Text('Create account and enjoy 7 days free trial',style: TextStyle(
                              color: Color(0xffB2B2DC),
                              fontSize: 15
                          ),),
                        ],
                      ),
                    ],
                  ),
                ),
                Expanded(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: [
                      Row(
                        children: [
                          Expanded(flex: 1 , child: Container(),),
                          Expanded(
                            flex: 10,
                            child: TextFormField(
                              keyboardType: TextInputType.name,
                              cursorColor: Colors.white,
                              style: TextStyle(fontSize: 18, color: Colors.white),
                              decoration: InputDecoration(
                                filled: true,
                                fillColor: Colors.white24,
                                border: OutlineInputBorder(
                                  borderRadius: BorderRadius.circular(10),
                                ),
                                contentPadding: EdgeInsets.symmetric(vertical: 25.0, horizontal: 20.0),
                                hintText: 'Your first and last name?',
                                labelText: 'Full Name',
                                labelStyle: TextStyle(color:Colors.white60 , fontSize: 18),
                                hintStyle: TextStyle(color:Colors.white60 , fontSize: 18),

                              ),
                              onSaved: (val) {
                                Email = val;
                              },
                              validator: (val) {
                                if (val == null || val.isEmpty) {
                                  return 'Please enter some text';
                                }
                              },
                            ),
                          ),
                          Expanded(flex: 1 , child: Container(),)
                        ],
                      ),
                      Row(
                        children: [
                          Expanded(flex: 1 , child: Container(),),
                          Expanded(
                            flex: 10,
                            child: TextFormField(
                              keyboardType: TextInputType.emailAddress,
                              cursorColor: Colors.white,
                              style: TextStyle(fontSize: 18, color: Colors.white),
                              decoration: InputDecoration(
                                filled: true,
                                fillColor: Colors.white24,
                                border: OutlineInputBorder(
                                  borderRadius: BorderRadius.circular(10),
                                ),
                                contentPadding: EdgeInsets.symmetric(vertical: 25.0, horizontal: 20.0),
                                labelText: 'Email',
                                labelStyle: TextStyle(color:Colors.white60 , fontSize: 18),
                                hintStyle: TextStyle(color:Colors.white60 , fontSize: 18),

                              ),
                              onSaved: (val) {
                                Email = val;
                              },
                              validator: (val) {
                                if (val == null || val.isEmpty) {
                                  return 'Please enter some text';
                                }
                              },
                            ),
                          ),
                          Expanded(flex: 1 , child: Container(),)
                        ],
                      ),
                      Row(
                        children: [
                          Expanded(flex: 1 , child: Container(),),
                          Expanded(
                            flex: 10,
                            child: TextFormField(
                              keyboardType: TextInputType.visiblePassword,
                              cursorColor: Colors.white,
                              style: TextStyle(fontSize: 18, color: Colors.white),
                              decoration: InputDecoration(
                                filled: true,
                                fillColor: Colors.white24,
                                border: OutlineInputBorder(
                                  borderRadius: BorderRadius.circular(10),
                                ),
                                contentPadding: EdgeInsets.symmetric(vertical: 25.0, horizontal: 20.0),
                                labelText: 'password',
                                labelStyle: TextStyle(color:Colors.white60 , fontSize: 18),
                                hintStyle: TextStyle(color:Colors.white60 , fontSize: 18),

                              ),
                              onSaved: (val) {
                                Email = val;
                              },
                              validator: (val) {
                                if (val == null || val.isEmpty) {
                                  return 'Please enter some text';
                                }
                              },
                            ),
                          ),
                          Expanded(flex: 1 , child: Container(),)
                        ],
                      ),
                      Row(
                        children: [
                          Expanded(flex: 1 , child: Container(),),
                          Expanded(
                            flex: 10,
                            child: TextFormField(
                              keyboardType: TextInputType.visiblePassword,
                              cursorColor: Colors.white,
                              style: TextStyle(fontSize: 18, color: Colors.white),
                              decoration: InputDecoration(
                                filled: true,
                                fillColor: Colors.white24,
                                border: OutlineInputBorder(
                                  borderRadius: BorderRadius.circular(10),
                                ),
                                contentPadding: EdgeInsets.symmetric(vertical: 25.0, horizontal: 20.0),
                                labelText: 're-password',
                                labelStyle: TextStyle(color:Colors.white60 , fontSize: 18),
                                hintStyle: TextStyle(color:Colors.white60 , fontSize: 18),

                              ),
                              onSaved: (val) {
                                Email = val;
                              },
                              validator: (val) {
                                if (val == null || val.isEmpty) {
                                  return 'Please enter some text';
                                }
                              },
                            ),
                          ),
                          Expanded(flex: 1 , child: Container(),)
                        ],
                      ),
                      Container(
                        margin: EdgeInsets.only(bottom: 50,top: 20),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Expanded(flex: 1 , child: Container(),),
                            Expanded(
                              flex: 10,
                              child: FlatButton(
                                shape: RoundedRectangleBorder(
                                    borderRadius: BorderRadius.circular(10.0)
                                ),
                                color: Colors.white,
                                height: 70,
                                onPressed: (){},
                                child: Column(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: [
                                    Container(
                                      child: Text('Sign up',textAlign:TextAlign.center,
                                        style: TextStyle(
                                          color: Color(0xff03045E),
                                          fontSize: 18.0,
                                        ),),
                                    ),
                                  ],
                                ),
                              ),
                            ),
                            Expanded(flex: 1 , child: Container(),),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),),
          ],
        ),
      ),
    );
  }
}

======== Exception caught by rendering library ===================================================== The following assertion was thrown during layout: A RenderFlex overflowed by 51 pixels on the bottom.

The relevant error-causing widget was: Column Column:file:///M:/Android PG/lockvpn0/lib/view/auth/sign-up.dart:87:26 The overflowing RenderFlex has an orientation of Axis.vertical. The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and black striped pattern. This is usually caused by the contents being too big for the RenderFlex.

Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the RenderFlex to fit within the available space instead of being sized to their natural size. This is considered an error condition because it indicates that there is content that cannot be seen. If the content is legitimately bigger than the available space, consider clipping it with a ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex, like a ListView.

The specific RenderFlex in question is: RenderFlex#d12d3 relayoutBoundary=up5 OVERFLOWING ... needs compositing ... parentData: offset=Offset(0.0, 260.0); flex=1; fit=FlexFit.tight (can use size) ... constraints: BoxConstraints(0.0<=w<=411.4, h=388.9) ... size: Size(411.4, 388.9) ... direction: vertical ... mainAxisAlignment: spaceEvenly ... mainAxisSize: max ... crossAxisAlignment: center ... verticalDirection: down ◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤

CodePudding user response:

You can wrap your column with a SingleChildScrollView. That should fix the overflow issue.

If you set resizeToAvoidBottomInset to true on your scaffold, the column won't be squished but you also won't be able to see your TextFields.

  • Related