Flutter Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#eaea6 NEEDS-LAYOUT NEEDS-PAINT

前端 未结 2 602
野性不改
野性不改 2021-01-19 14:09

I\'m using SingleChildScrollView and a Column to display a swiper and a gridview.

If I use some other widget like text, image in my column, the app shows ok. But my

2条回答
  •  面向向阳花
    2021-01-19 14:44

    You cannot have an Expanded widget within the SingleChildScrollView which has boundless vertical dimensions.

    class _HomePageState extends State {
      final List _children;
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
            body: Column(
              mainAxisSize: MainAxisSize.min,
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                Expanded(
                    child: Container(
                  height: 200,
                  child: Swiper(
                    itemBuilder: (BuildContext context, int index) {
                      return Image.network(
                        "http://via.placeholder.com/350x150",
                        fit: BoxFit.fitHeight,
                      );
                    },
                    itemCount: 5,
                    pagination: SwiperPagination(),
                    control: SwiperControl(),
                  ),
                )),
                Expanded(
                  child: GridView.builder(
                    gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                        crossAxisCount: 4, childAspectRatio: 1.0),
                    itemBuilder: (BuildContext context, int index) {
                      return ListItemWidget(_children[index]);
                    },
                    itemCount: _children.length,
                  ),
                ),
              ],
          ),
        );
      }
    }
    

提交回复
热议问题