Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextField gets hidden when the keyboard pops in

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,
                  )
                ],
              )
            ],
          ),
        ),
      ],
    ));
 }
}

Hello all this is my first flutter app. I have been trying to create a sign up page with few textfields. Everything looks good, but whenever I click on any textfield softkeyboard shows and hide the text filed(please see the attached images) keyboard hiding the textfield textfields without keyboard

like image 326
Wubbalubbadubdub Avatar asked Mar 05 '23 17:03

Wubbalubbadubdub


1 Answers

A few changes:

  • Set resizeToAvoidBottomPadding true

  • Remove the Flexible Widget

  • Wrap your first Column inside 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,
                              )
                            ],
                          )
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ));
      }
    
like image 62
diegoveloper Avatar answered Mar 16 '23 18:03

diegoveloper