Прокрутка текстовых полей в поле зрения, когда клавиатура появляется - PullRequest
0 голосов
/ 01 мая 2020

У меня есть эта страница входа в систему, когда я нажимаю на текстовое поле, оно должно быть в верхней части клавиатуры, я пытался с помощью следующего кода, но это не сработало, я пробовал с singlechildview, то же самое также с listview, также не работал Я пытался удалить стек и устал с контейнером, но он такой же, теперь у меня есть этот код,

 Size size = MediaQuery.of(context).size;
    return new Scaffold(
      resizeToAvoidBottomInset: false,
      body: new Stack(
        children: <Widget>[
          Center(
            child: new Image.asset(
              'assets/images/splash_bg.png',
              width: size.width,
              height: size.height,
              fit: BoxFit.fill,
            ),
          ),
          Center(
            child: new Image.asset(
              'assets/images/clublogo.png',
              width: 150,
              height: 150,
            ),
          ),
          Center(
            child: Padding(
              padding: EdgeInsets.only(top: 250, left: 10, right: 10),
              child: TextField(
                textAlign: TextAlign.center,
                style: TextStyle(color: Colors.white),
                decoration: InputDecoration(
                  focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(
                        color: Colors.orangeAccent[200], width: 2.0),
                    borderRadius: const BorderRadius.all(
                      const Radius.circular(20.0),
                    ),
                  ),
                  enabledBorder: OutlineInputBorder(
                    borderSide: BorderSide(
                        color: Colors.orangeAccent[200], width: 2.0),
                    borderRadius: const BorderRadius.all(
                      const Radius.circular(20.0),
                    ),
                  ),

                  contentPadding: EdgeInsets.all(5),
                  hintText: " Enter Mobile Number",
                  hintStyle: TextStyle(color: Colors.white, fontSize: 15),
                  suffixIcon: Container(
                    decoration: BoxDecoration(
                        border: Border.all(
                          color: Colors.orangeAccent[200],
                        ),
                        borderRadius: BorderRadius.all(
                          Radius.circular(20),
                        )),
                    child: FittedBox(
                      alignment: Alignment.center,
                      fit: BoxFit.fitHeight,
                      child: IconButton(
                        icon: Icon(MdiIcons.arrowRight),
                        iconSize: 33.0,
                        color: Colors.orangeAccent[200],
                        onPressed: () {
                          FocusScope.of(context).requestFocus(FocusNode());
                          print("gfgfg");
                        },
                      ),
                    ),
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
    );

Ответы [ 2 ]

0 голосов
/ 01 мая 2020

Измените resizeToAvoidBottomInset на true, чтобы решить проблему. Это заставляет текстовое поле двигаться вверх при открытии клавиатуры.

enter image description here

0 голосов
/ 01 мая 2020

Пожалуйста, вставьте ниже код и измените его в соответствии с вашими виджетами.

@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SingleChildScrollView(
        child: Container(
          width: MediaQuery.of(context).size.width,
          child: Column(
            children: <Widget>[
              Container(
                margin: EdgeInsets.only(top: 80),
                child: FlutterLogo(
                  size: 200,
                ),
              ),
              Container(
                padding: EdgeInsets.all(10),
                margin: EdgeInsets.only(top: 10),
                child: TextField(
                  controller: _emailController,
                  decoration: InputDecoration(
                    border: OutlineInputBorder(),
                    hintText: "Email",
                    labelText: "Enter Email",
                  ),
                  keyboardType: TextInputType.emailAddress,
                ),
              ),
              Container(
                padding: EdgeInsets.all(10),
                margin: EdgeInsets.only(top: 10),
                child: TextField(
                  controller: _passwordController,
                  decoration: InputDecoration(
                    border: OutlineInputBorder(),
                    hintText: "Password",
                    labelText: "Enter Password",
                  ),
                  obscureText: true,
                ),
              ),
              InkWell(
                onTap: () {
                  _signIn();
                },
                child: Container(
                  decoration: BoxDecoration(
                      gradient: LinearGradient(
                        colors: [Colors.blueAccent, Colors.blue, Colors.black],
                      ),
                      borderRadius: BorderRadius.circular(8)),
                  padding: EdgeInsets.symmetric(horizontal: 30, vertical: 20),
                  margin: EdgeInsets.symmetric(horizontal: 30, vertical: 20),
                  width: MediaQuery.of(context).size.width,
                  child: Center(child: Text("Login with Email")),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...