RenderFlex переполнен на 16 пикселей внизу. Переполнение RenderFlex имеет ориентацию Axis.vertical - PullRequest
0 голосов
/ 20 апреля 2020

Я пытаюсь выровнять компоненты по вертикали, но мне это не удалось, я назвал следующие виджеты, которые хочу выровнять A, B, C. Ниже приведена картинка для демонстрации:

enter image description here

Итак, как вы можете видеть картинку A - это просто карта, затем B - это ListView, который можно прокручивать, затем C, это текст плюс Горизонтальный ListView , но не видимый, поскольку вы можете видеть желтые черные линии внизу. ( Итак, это то, от чего я хочу избавиться )

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

  • Expanded.
  • SingleChildScrollView

но ничего не работает.

Я завернул A, B и C в столбце и попытался использовать Expanded (, как я объяснил выше ), хотя C все еще не виден.

ниже мой код:

 @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        TopStory(),
        Expanded(
          flex: 5,
          child: Container(
            constraints: BoxConstraints(
              maxHeight: 300.0
            ),
            child: ListView(
              shrinkWrap: true,
              children: <Widget>[
                Container(
                    alignment: Alignment.topLeft,
                    padding: EdgeInsets.only(top: 30.0, left: 20.0, bottom: 10.0),
                    // width: 50.0,
                    child: Text(
                      'Recent Stories',
                      style: TextStyle(
                        fontSize: 17.0,
                        fontWeight: FontWeight.bold,
                      ),
                    )),
                Container(
                    margin: EdgeInsets.only(left: 20.0, right: 20.0),
                    padding: EdgeInsets.only(top: 10.0, bottom: 10.0),
                    decoration: BoxDecoration(
                      border: Border(
                          top: BorderSide(
                        color: Colors.black26,
                      )),
                    ),
                    child: ArticleList()),
                Container(
                    margin: EdgeInsets.only(left: 20.0, right: 20.0),
                    padding: EdgeInsets.only(top: 10.0, bottom: 10.0),
                    decoration: BoxDecoration(
                      border: Border(
                          top: BorderSide(
                        color: Colors.black26,
                      )),
                    ),
                    child: ArticleList()),
                Container(
                    margin: EdgeInsets.only(left: 20.0, right: 20.0),
                    padding: EdgeInsets.only(top: 10.0, bottom: 10.0),
                    decoration: BoxDecoration(
                      border: Border(
                          top: BorderSide(
                        color: Colors.black26,
                      )),
                    ),
                    child: ArticleList()),
                Container(
                    margin: EdgeInsets.only(left: 20.0, right: 20.0),
                    padding: EdgeInsets.only(top: 10.0, bottom: 10.0),
                    decoration: BoxDecoration(
                      border: Border(
                          top: BorderSide(
                        color: Colors.black26,
                      )),
                    ),
                    child: ArticleList()),
              ],
            ),
          ),
        ),
        Expanded(
          flex: 1,
            child: MoreCategoriesPage(),
        )

      ],
    );
  }

Как видите, код A равен TopStory(), тогда B равен ListView, наконец, C - это MoreCategoriesPage(). И в моем случае, я думаю, MoreCategoriesPage() хорошо выровнен, но позвольте мне также отобразить код, поскольку он имеет горизонтальный ListView .

Ниже MoreCategoriesPage класс:

class MoreCategoriesPage extends StatefulWidget {
  @override
  _MoreCategoriesPageState createState() => _MoreCategoriesPageState();
}

class _MoreCategoriesPageState extends State<MoreCategoriesPage> {
  List<MoreCategoryModel> _list = new List();
  int moreCatColorOne = 0xFF8A0000;
  int moreCatColorTwo = 0xFFB00222;
  int moreCatColorThree = 0xFFC21828;
  int moreCatColorFour = 0xFFD2232A;
  int moreCatColorFive = 0xFFD2232A;
  Color moreCatColorText = const Color(0xFF9E9E9E);

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    _list.add(MoreCategoryModel(Icons.business, "Bussiness", moreCatColorOne));
    _list.add(
        MoreCategoryModel(Icons.insert_chart, "Statistics", moreCatColorTwo));
    _list.add(MoreCategoryModel(Icons.school, "Education", moreCatColorThree));
    _list.add(MoreCategoryModel(
        Icons.directions_transit, "Transport", moreCatColorFour));
    _list.add(MoreCategoryModel(
        Icons.supervisor_account, "Social", moreCatColorFive));

    return Container(
      child: Column(
        children: <Widget>[
          Container(
            alignment: Alignment.topLeft,
            padding: EdgeInsets.only(top: 30.0, left: 20.0, bottom: 10.0),
            // width: 50.0,
            child: Text(
              'More Categories',
              style: TextStyle(
                fontSize: 17.0,
                fontWeight: FontWeight.bold,
              ),
            )),
          Expanded(child: buildMoreCategoryList(_list))
        ],
      ),
    );
  }

  Widget buildMoreCategoryList(List<MoreCategoryModel> more_categories) {
    return ListView.builder(
        scrollDirection: Axis.horizontal,
        itemCount: 5,
        itemBuilder: (ctx, position) {
          return Row(
            children: <Widget>[
              Column(
                children: <Widget>[
                  Card(
                      clipBehavior: Clip.antiAliasWithSaveLayer,
                      elevation: 2,
                      color: Color(more_categories[position].color),
                      margin: EdgeInsets.all(10),
                      child: Padding(
                        padding: const EdgeInsets.all(23.0),
                        child: Icon(
                          more_categories[position].iconCategory,
                          color: Colors.white,
                        ),
                      )),
                  Text(
                    more_categories[position].nameCategory,
                    style: TextStyle(color: moreCatColorText),
                  )
                ],
              ),
            ],
          );
        });
  }

Это ошибка, которую я получаю:

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

The relevant error-causing widget was: 
  Column file:///D:/workspace/newvisionapp/lib/src/ui/more_category/more_category.dart:37:14
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#28b08 relayoutBoundary=up1 OVERFLOWING
...  needs compositing
...  parentData: offset=Offset(0.0, 439.5); flex=1; fit=FlexFit.tight (can use size)
...  constraints: BoxConstraints(0.0<=w<=411.4, h=43.9)
...  size: Size(411.4, 43.9)
...  direction: vertical
...  mainAxisAlignment: start
...  mainAxisSize: max
...  crossAxisAlignment: center
...  verticalDirection: down
◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...