Дно перегружено на 213 пикселей во флаттере

Привет, я пытаюсь создать экран входа в систему. У меня все работает нормально. Когда я открываю клавиатуру, появляется ошибка Bottom overloaded by 213 pixels.

  Widget LoginPage() {
    return new Scaffold(body: Container(
      height: MediaQuery.of(context).size.height,
      decoration: BoxDecoration(
        color: Colors.white,
        image: DecorationImage(
          colorFilter: new ColorFilter.mode(
              Colors.black.withOpacity(0.05), BlendMode.dstATop),
          image: AssetImage('assets/images/mountains.jpg'),
          fit: BoxFit.cover,
        ),
      ),
      child: new Column(
        children: <Widget>[
          Container(
            padding: EdgeInsets.all(120.0),
            child: Center(
              child: Icon(
                Icons.headset_mic,
                color: Colors.redAccent,
                size: 50.0,
              ),
            ),
          ),
          new Row(
            children: <Widget>[
              new Expanded(
                child: new Padding(
                  padding: const EdgeInsets.only(left: 40.0),
                  child: new Text(
                    "EMAIL",
                    style: TextStyle(
                      fontWeight: FontWeight.bold,
                      color: Colors.redAccent,
                      fontSize: 15.0,
                    ),
                  ),
                ),
              ),
            ],
          ),
          new Container(
            width: MediaQuery.of(context).size.width,
            margin: const EdgeInsets.only(left: 40.0, right: 40.0, top: 10.0),
            alignment: Alignment.center,
            decoration: BoxDecoration(
              border: Border(
                bottom: BorderSide(
                    color: Colors.redAccent,
                    width: 0.5,
                    style: BorderStyle.solid),
              ),
            ),
            padding: const EdgeInsets.only(left: 0.0, right: 10.0),
            child: new Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                new Expanded(
                  child: TextField(
                    obscureText: true,
                    textAlign: TextAlign.left,
                    decoration: InputDecoration(
                      border: InputBorder.none,
                      hintText: '[email protected]',
                      hintStyle: TextStyle(color: Colors.grey),
                    ),
                  ),
                ),
              ],
            ),
          ),
          Divider(
            height: 24.0,
          ),
          new Row(
            children: <Widget>[
              new Expanded(
                child: new Padding(
                  padding: const EdgeInsets.only(left: 40.0),
                  child: new Text(
                    "PASSWORD",
                    style: TextStyle(
                      fontWeight: FontWeight.bold,
                      color: Colors.redAccent,
                      fontSize: 15.0,
                    ),
                  ),
                ),
              ),
            ],
          ),
          new Container(
            width: MediaQuery.of(context).size.width,
            margin: const EdgeInsets.only(left: 40.0, right: 40.0, top: 10.0),
            alignment: Alignment.center,
            decoration: BoxDecoration(
              border: Border(
                bottom: BorderSide(
                    color: Colors.redAccent,
                    width: 0.5,
                    style: BorderStyle.solid),
              ),
            ),
            padding: const EdgeInsets.only(left: 0.0, right: 10.0),
            child: new Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                new Expanded(
                  child: TextField(
                    obscureText: true,
                    textAlign: TextAlign.left,
                    decoration: InputDecoration(
                      border: InputBorder.none,
                      hintText: '*********',
                      hintStyle: TextStyle(color: Colors.grey),
                    ),
                  ),
                ),
              ],
            ),
          ),
          Divider(
            height: 24.0,
          ),
          new Row(
            mainAxisAlignment: MainAxisAlignment.end,
            children: <Widget>[
              Padding(
                padding: const EdgeInsets.only(right: 20.0),
                child: new FlatButton(
                  child: new Text(
                    "Forgot Password?",
                    style: TextStyle(
                      fontWeight: FontWeight.bold,
                      color: Colors.redAccent,
                      fontSize: 15.0,
                    ),
                    textAlign: TextAlign.end,
                  ),
                  onPressed: () => {},
                ),
              ),
            ],
          ),
          new Container(
            width: MediaQuery.of(context).size.width,
            margin: const EdgeInsets.only(left: 30.0, right: 30.0, top: 20.0),
            alignment: Alignment.center,
            child: new Row(
              children: <Widget>[
                new Expanded(
                  child: new FlatButton(
                    shape: new RoundedRectangleBorder(
                      borderRadius: new BorderRadius.circular(30.0),
                    ),
                    color: Colors.redAccent,
                    onPressed: () => {},
                    child: new Container(
                      padding: const EdgeInsets.symmetric(
                        vertical: 20.0,
                        horizontal: 20.0,
                      ),
                      child: new Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: <Widget>[
                          new Expanded(
                            child: Text(
                              "LOGIN",
                              textAlign: TextAlign.center,
                              style: TextStyle(
                                  color: Colors.white,
                                  fontWeight: FontWeight.bold),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
          new Container(
            width: MediaQuery.of(context).size.width,
            margin: const EdgeInsets.only(left: 30.0, right: 30.0, top: 20.0),
            alignment: Alignment.center,
            child: Row(
              children: <Widget>[
                new Expanded(
                  child: new Container(
                    margin: EdgeInsets.all(8.0),
                    decoration: BoxDecoration(border: Border.all(width: 0.25)),
                  ),
                ),
                Text(
                  "OR CONNECT WITH",
                  style: TextStyle(
                    color: Colors.grey,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                new Expanded(
                  child: new Container(
                    margin: EdgeInsets.all(8.0),
                    decoration: BoxDecoration(border: Border.all(width: 0.25)),
                  ),
                ),
              ],
            ),
          ),
          new Container(
            width: MediaQuery.of(context).size.width,
            margin: const EdgeInsets.only(left: 30.0, right: 30.0, top: 20.0),
            child: new Row(
              children: <Widget>[
                new Expanded(
                  child: new Container(
                    margin: EdgeInsets.only(right: 8.0),
                    alignment: Alignment.center,
                    child: new Row(
                      children: <Widget>[
                        new Expanded(
                          child: new FlatButton(
                            shape: new RoundedRectangleBorder(
                              borderRadius: new BorderRadius.circular(30.0),
                            ),
                            color: Color(0Xff3B5998),
                            onPressed: () => {},
                            child: new Container(
                              child: new Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: <Widget>[
                                  new Expanded(
                                    child: new FlatButton(
                                      padding: EdgeInsets.only(
                                        top: 20.0,
                                        bottom: 20.0,
                                      ),
                                      child: new Row(
                                        mainAxisAlignment:
                                        MainAxisAlignment.spaceEvenly,
                                        children: <Widget>[
                                          Icon(
                                            const IconData(0xea90,
                                                fontFamily: 'icomoon'),
                                            color: Colors.white,
                                            size: 15.0,
                                          ),
                                          Text(
                                            "FACEBOOK",
                                            textAlign: TextAlign.center,
                                            style: TextStyle(
                                                color: Colors.white,
                                                fontWeight: FontWeight.bold),
                                          ),
                                        ],
                                      ),
                                    ),
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
                new Expanded(
                  child: new Container(
                    margin: EdgeInsets.only(left: 8.0),
                    alignment: Alignment.center,
                    child: new Row(
                      children: <Widget>[
                        new Expanded(
                          child: new FlatButton(
                            shape: new RoundedRectangleBorder(
                              borderRadius: new BorderRadius.circular(30.0),
                            ),
                            color: Color(0Xffdb3236),
                            onPressed: () => {},
                            child: new Container(
                              child: new Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: <Widget>[
                                  new Expanded(
                                    child: new FlatButton(
                                      padding: EdgeInsets.only(
                                        top: 20.0,
                                        bottom: 20.0,
                                      ),
                                      child: new Row(
                                        mainAxisAlignment:
                                        MainAxisAlignment.spaceEvenly,
                                        children: <Widget>[
                                          Icon(
                                            const IconData(0xea88,
                                                fontFamily: 'icomoon'),
                                            color: Colors.white,
                                            size: 15.0,
                                          ),
                                          Text(
                                            "GOOGLE",
                                            textAlign: TextAlign.center,
                                            style: TextStyle(
                                                color: Colors.white,
                                                fontWeight: FontWeight.bold),
                                          ),
                                        ],
                                      ),
                                    ),
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          )
        ],
      ),
    ));
  }

Кто-нибудь знает, в чем может быть проблема?

Дно перегружено на 213 пикселей во флаттере

46
0
57 822
15

Ответы 15

обычно вам нужно предоставить виджет прокрутки поверх виджетов, потому что, если вы попытаетесь открыть клавиатуру или изменить ориентацию телефона, flutter должен знать, как обрабатывать распределение виджетов на экране.

Пожалуйста, просмотрите этот ресурс, вы можете проверить различные варианты, которые предлагает Flutter из коробки, и выбрать лучший вариант для вашего сценария.

https://flutter.io/widgets/scrolling/

Я не понимаю, какой из них мне следует использовать? Я хочу, чтобы мой экран прокручивался, как будто в Android есть ScrollView. Подскажите, пожалуйста?

N Sharma 10.08.2018 19:58

Сначала это сбивает с толку, но когда вы создаете много страниц, вы можете узнать, какой виджет более полезен, чем другой, в соответствии с кодом, которым вы поделились, вы можете использовать listView вместо виджета Column.

Roger Villamarin 11.08.2018 23:23

Я бы предложил заменить верхний виджет Column на ListView, который автоматически изменяет размер при вводе с клавиатуры, а также поддерживает прокрутку.

Если вы действительно хотите, чтобы эта настройка была такой, какая она есть, вы можете отредактировать свой Scaffold с помощью параметра

resizeToAvoidBottomPadding: false 

Это должно заставить исчезнуть ошибку

Проблема все еще, :(

Álvaro Agüero 10.06.2019 03:13

Прочтите ответ, который я разместил ниже, это не решит проблему

AlexPad 31.07.2019 09:50

Идеальный! Это более простое решение в больших случаях ... Посмотрите этот фильм об этой проблеме: youtube.com/watch?v=2E9iZgg5TOY

Wedson Quintanilha da Silva 14.01.2020 15:02

вы можете обернуть основной виджет Column с помощью Singlechildscrollview, это будет работать, даже если у вас есть несколько текстовых полей.

allence vakharia 27.01.2020 06:41

Вы великолепны, замена "Column" на "ListView" сработала для меня

Excite 01.07.2020 16:10

Вы можете заключить все виджеты в ListView.
Так что вы можете его прокрутить, и перегруженное исчезнет.

оберните свое дочернее представление в ListView, чтобы решить проблему. Пожалуйста, проверьте это

 class _LoginScreenState extends State<LoginScreen> {
 @override
 Widget build(BuildContext context) {
    return new Scaffold(
    body: new Container(
     child: ListView(
       children: <Widget>[
        Padding(
          padding: const EdgeInsets.all(8.0),
          child: new Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[

                new Padding(
                  padding: EdgeInsets.only(left: 1,top: 50,right: 1,bottom: 1),
                  child: new Text("jk", style: TextStyle(fontFamily: "mono_bold")),
                ),

                 new Padding(
                  padding: EdgeInsets.only(left: 1,top: 50,right: 1,bottom: 1),
                  child: new TextField(
                    style: new TextStyle(),
                      decoration: InputDecoration(
                        labelText: "Email",
                        contentPadding: EdgeInsets.all(8.0)
                    ),
                    keyboardType: TextInputType.emailAddress,
                  )
                ),
                 new Padding(
                  padding: EdgeInsets.only(left: 1,top: 50,right: 1,bottom: 1),
                  child: new TextField(
                    style: new TextStyle(

                    ),
                    decoration: InputDecoration(
                      labelText: "Password"

                    ),
                    keyboardType: TextInputType.text,
                    obscureText: true,
                    ),
                ),
              ],
          ),
        ),
      ],
    )
  ),
);
}

С resizeToAvoidBottomPadding: false в Scaffold вы не видите все виджеты, которые находятся под открытым текстовым полем. Решение - вставить контейнер с SingleChildScrollView внутри. Пример:

Container(
    alignment: Alignment.center,
    width: double.infinity,
    height: double.infinity,
    color: viewModel.color,
    child: SingleChildScrollView(child:"Your widgets"));

Обертывание тела скаффолда с помощью SingleChildScrollVie Проблема решена. +1

Gal Rom 21.05.2020 20:59
Scaffold(
  resizeToAvoidBottomInset: false, // set it to false
  ... 
)

Как сказал Андрей, у вас могут быть проблемы с прокруткой, поэтому вы можете попробовать

Scaffold(
  resizeToAvoidBottomInset: false, // set it to false
  body: SingleChildScrollView(child: YourBody()),
)

Я пробовал это. Мое тело представляет собой виджет Column, и я получил эту ошибку: RenderBox не был выложен: RenderRepaintBoundary # 5cb99 relayoutBoundary = up1 NEEDS-PAINT 'package: flutter / src / rendering / box.dart': Failed assertion: line 1785 pos 12: ' hasSize '

Mr. ZeroOne 16.11.2020 12:47

Вы можете настроить resizeToAvoidBottomInset: false, чтобы избежать переполнения, но вы не можете добраться до полей внизу страницы, которые могут быть закрыты клавиатурой.

Или вы можете обернуть корпус Scaffold внутрь SingleChildScrollView

Попробуйте обернуть основной столбец

1. (ListView и укажите свойство shrinkWrap: true). Представление списка имеет дочерние свойства: [] или

2. (SingleChildScrollView ()), но у него есть только дочерний элемент:,.

Что-то типа:

 child: ListView(shrinkWrap: true, children: <Widget>[
                new Column(children: <Widget>[
                  Container(
                    padding: EdgeInsets.all(120.0),
                    child: Center(
                      child: Icon(
                        Icons.headset_mic,
                        color: Colors.redAccent,
                        size: 50.0,
                      ),
                    ),
                  ),
                  new Row(
                    children: <Widget>[
                      new Expanded(
                        child: new Padding(
                          padding: const EdgeInsets.only(left: 40.0),
                          child: new Text(
                            "EMAIL",
                            style: TextStyle(
                              fontWeight: FontWeight.bold,
                              color: Colors.redAccent,
                              fontSize: 15.0,
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                  new Container(
                    width: MediaQuery.of(context).size.width,
                    margin: const EdgeInsets.only(
                        left: 40.0, right: 40.0, top: 10.0),
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                      border: Border(
                        bottom: BorderSide(
                            color: Colors.redAccent,
                            width: 0.5,
                            style: BorderStyle.solid),
                      ),
                    ),
                    padding: const EdgeInsets.only(left: 0.0, right: 10.0),
                    child: new Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: <Widget>[
                        new Expanded(
                          child: TextField(
                            obscureText: true,
                            textAlign: TextAlign.left,
                            decoration: InputDecoration(
                              border: InputBorder.none,
                              hintText: '[email protected]',
                              hintStyle: TextStyle(color: Colors.grey),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                  Divider(
                    height: 24.0,
                  ),
                  new Row(
                    children: <Widget>[
                      new Expanded(
                        child: new Padding(
                          padding: const EdgeInsets.only(left: 40.0),
                          child: new Text(
                            "PASSWORD",
                            style: TextStyle(
                              fontWeight: FontWeight.bold,
                              color: Colors.redAccent,
                              fontSize: 15.0,
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                  new Container(
                    width: MediaQuery.of(context).size.width,
                    margin: const EdgeInsets.only(
                        left: 40.0, right: 40.0, top: 10.0),
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                      border: Border(
                        bottom: BorderSide(
                            color: Colors.redAccent,
                            width: 0.5,
                            style: BorderStyle.solid),
                      ),
                    ),
                    padding: const EdgeInsets.only(left: 0.0, right: 10.0),
                    child: new Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: <Widget>[
                        new Expanded(
                          child: TextField(
                            obscureText: true,
                            textAlign: TextAlign.left,
                            decoration: InputDecoration(
                              border: InputBorder.none,
                              hintText: '*********',
                              hintStyle: TextStyle(color: Colors.grey),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ])
              ]),

Поместите свой контент в SingleChildScrollView, добавьте ConstrainedBox и попробуйте

https://api.flutter.dev/flutter/widgets/SingleChildScrollView-class.html

оберните свой столбец в SingleChildScrollView, чтобы решить проблему. Пожалуйста, проверьте это:

 Widget build(BuildContext context) {
    return Scaffold(
        body: Container(
            child: Center(
                child: SingleChildScrollView(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              TextField(),
              TextField(),
            ],
          ),
        ))));
  }

И вы также используете для удаления желто-черной линии перелива

resizeToAvoidBottomPadding: false 

но в этом случае TextField не увеличивает время щелчка.

Оберните верхнюю колонку внутрь SingleChildScrollView.

Сделайте макет прокручиваемым.

Вы можете обернуть свои поля в один дочерний ScrollView Flutter.

оберните виджетом SingleChildScrollView вот мой код для решения этой ситуации: это лучший и самый простой способ

SingleChildScrollView(
              child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: <Widget>[
          Hero(
            tag: 'logo',
                        child: Container(
              height: 200.0,
              child: Image.asset('images/logo.png'),
            ),
          ),
          SizedBox(
            height: 48.0,
          ),
          TextField(
            onChanged: (value) {
              //Do something with the user input.
            },
            decoration:  kTextFieldDecoration.copyWith(hintText: 'Enter username'),
          ),
          SizedBox(
            height: 8.0,
          ),
          TextField(
            onChanged: (value) {
              //Do something with the user input.
            },
            decoration: kTextFieldDecoration.copyWith(hintText: 'Enter password'),
          ),
          SizedBox(
            height: 24.0,
          ),

           RoundedButton(
            colour: Colors.blueAccent,
            text: 'Register',
            onPressed: () {
            //later todo
            },
          ),

        ],
      ),
    ),

Это выравнивает элементы снизу вверх, Попробуй это..

child: SizedBox(
      height: MediaQuery.of(context).size.height,
                  child: SingleChildScrollView(
                    reverse: true,

Удалите ненужную обивку сверху и снизу

    child: Container(

          height: size.height,
             width: size.width,
          padding: EdgeInsets.only(
                left: size.width * 0.15,
              right: size.width * 0.15,
              top: size.width * 0.15,
              bottom: size.width * 0.15,
         ),

изменить этим

     child: Container(
    
              height: size.height,
                 width: size.width,
              padding: EdgeInsets.only(
                    left: size.width * 0.15,
                  right: size.width * 0.15,
             ),

Это сработало для меня.

Другие вопросы по теме