Подтвердить что ты не робот

Вертикальному видовому пространству была задана неограниченная высота

Я новичок, чтобы трепетать. Просто нужно центрировать мой вид сетки:

enter image description here

Ниже приведен код, который я пробовал:

  @override
  Widget build(BuildContext context) {
    return new Material(
      color: Colors.deepPurpleAccent,
      child: new Column(
       mainAxisAlignment: MainAxisAlignment.center,
          children:<Widget>[new GridView.count(crossAxisCount: _column,children: new List.generate(_row*_column, (index) {
            return new Center(
                child: new CellWidget()
            );
          }),)]
      )
    );
  }

Исключение составляют следующие:

    I/flutter ( 9925): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter ( 9925): The following assertion was thrown during performResize():
I/flutter ( 9925): Vertical viewport was given unbounded height.
I/flutter ( 9925): Viewports expand in the scrolling direction to fill their container.In this case, a vertical
I/flutter ( 9925): viewport was given an unlimited amount of vertical space in which to expand. This situation
I/flutter ( 9925): typically happens when a scrollable widget is nested inside another scrollable widget.
I/flutter ( 9925): If this widget is always nested in a scrollable widget there is no need to use a viewport because
I/flutter ( 9925): there will always be enough vertical space for the children. In this case, consider using a Column
I/flutter ( 9925): instead. Otherwise, consider using the "shrinkWrap" property (or a ShrinkWrappingViewport) to size
I/flutter ( 9925): the height of the viewport to the sum of the heights of its children.
I/flutter ( 9925): 
I/flutter ( 9925): When the exception was thrown, this was the stack:
I/flutter ( 9925): #0      RenderViewport.performResize.<anonymous closure> (package:flutter/src/rendering/viewport.dart:827:15)
I/flutter ( 9925): #1      RenderViewport.performResize (package:flutter/src/rendering/viewport.dart:880:6)
I/flutter ( 9925): #2      RenderObject.layout (package:flutter/src/rendering/object.dart:1555:9)

Заранее спасибо!

4b9b3361

Ответ 1

добавив эти две строки

ListView.builder(
    scrollDirection: Axis.vertical,
    shrinkWrap: true,
...

Ответ 2

отображение сетки внутри гибкого или расширенного виджета

return new Material(
    color: Colors.deepPurpleAccent,
    child: new Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children:<Widget>[
         Flexible(
          child:  GridView.count(crossAxisCount: _column,children: new List.generate(_row*_column, (index) {
          return new Center(
             child: new CellWidget(),
          );
        }),))]
    )
);

Ответ 3

Обычно это происходит, когда вы пытаетесь использовать ListView/GridView внутри Column, есть много способов ее решения, я перечисляю несколько здесь.

  1. Оберните ListView в Expanded

    Column(
      children: <Widget>[
        Expanded( // wrap in Expanded
          child: ListView(...),
        ),
      ],
    )
    
  2. Оберните ListView в SizedBox и дайте ограниченный height

    Column(
      children: <Widget>[
        SizedBox(
          height: 400, // fixed height
          child: ListView(...),
        ),
      ],
    )
    
  3. Используйте shrinkWrap: true в ListView.

    Column(
      children: <Widget>[
        ListView(
          shrinkWrap: true, // use this
        ),
      ],
    )
    

Ответ 4

Не используйте Column для выравнивания одного ребенка. Вместо этого используйте Align.

    new Align(
      alignment: Alignment.topCenter,
      child: new GridView(),
    )

Ответ 5

Ваша колонна не знает, сколько высоты она займет. Используйте Flexible, чтобы обернуть столбец так, чтобы он имел гибкость для расширения и заполнения доступного пространства на главной оси.

  @override
  Widget build(BuildContext context) {
    return new Material(
        color: Colors.deepPurpleAccent,
        child: Flexible(
            child: new Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children:<Widget>[new GridView.count(crossAxisCount: _column,children: new List.generate(_row*_column, (index) {
                  return new Center(
                      child: new CellWidget()
                  );
                }),)]
            )
        )
    );
  }