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

前端 未结 2 591
野性不改
野性不改 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:30

    I had exactly the same problem, and for me what worked was to wrap the swiper first with the expanded widget, and then wrap the expanded with the container with the sizes needed 1.Container 2. Expanded 3. Swiper

    0 讨论(0)
  • 2021-01-19 14:44

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

    class _HomePageState extends State<HomePage> {
      final List<ListItem> _children;
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
            body: Column(
              mainAxisSize: MainAxisSize.min,
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: <Widget>[
                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,
                  ),
                ),
              ],
          ),
        );
      }
    }
    
    0 讨论(0)
提交回复
热议问题