微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

RenderBox尚未布置:StaggeredGridView Widget

如何解决RenderBox尚未布置:StaggeredGridView Widget

我遇到了这样的错误

RenderBox was not laid out: RenderViewport#b889d NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:Flutter/src/rendering/Box.dart':
Failed assertion: line 1702 pos 12: 'hasSize'

这是错误的描述。

The following assertion was thrown during performResize():
Vertical viewport was given unbounded height.
Viewports expand in the scrolling direction to fill their container. In this case,a vertical
viewport was given an unlimited amount of vertical space in which to expand. This situation
typically happens when a scrollable widget is nested inside another scrollable widget.
If this widget is always nested in a scrollable widget there is no need to use a viewport because
there will always be enough vertical space for the children. In this case,consider using a Column
instead. Otherwise,consider using the "shrinkWrap" property (or a ShrinkWrappingViewport) to size
the height of the viewport to the sum of the heights of its children.
The relevant error-causing widget was:
  StaggeredGridView 

正如在错误描述中清楚提到的那样,问题在于StaggeredGridView。我在使用ListView时遇到了类似的错误,但可以通过使用Expanded对其进行包装来解决。该如何解决错误

这是我的代码

import 'package:Flutter/material.dart';
import 'package:Flutter_staggered_grid_view/Flutter_staggered_grid_view.dart';
import 'package:transparent_image/transparent_image.dart';

class Food extends StatefulWidget {
  static const routeName = '/food';

  @override
  _FoodState createState() => _FoodState();
}

class _FoodState extends State<Food> {
  List<String> imageList = [
    "assets/images/food.jpg","assets/images/food.jpg",];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color.fromrGBO(244,243,1),appBar: AppBar(
        title: Text("Food"),elevation: 0,brightness: Brightness.light,),body: SafeArea(
        child: SingleChildScrollView(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,children: <Widget>[
              Container(
                width: double.infinity,decoration: Boxdecoration(
                  color: Colors.white,padding: EdgeInsets.all(20.00),child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,children: <Widget>[
                    Text(
                      "Find your favourite",style: TextStyle(
                        color: Colors.black87,fontSize: 25,SizedBox(
                      height: 3,Text(
                      "Food",fontSize: 40,fontWeight: FontWeight.bold,SizedBox(
                      height: 20,Container(
                      margin: EdgeInsets.all(12),child: Expanded(
                        child: new StaggeredGridView.countBuilder(
                          crossAxisCount: 2,crossAxisspacing: 12.0,mainAxisspacing: 12.0,itemBuilder: (context,index) {
                            return Container(
                                decoration: Boxdecoration(
                                  color: Colors.transparent,borderRadius: BorderRadius.circular(20),child: ClipRRect(
                                  borderRadius: BorderRadius.circular(20),child: FadeInImage.memoryNetwork(
                                    placeholder: kTransparentimage,image: imageList[index],));
                          },staggeredTileBuilder: (index) {
                            return new StaggeredTile.count(
                                1,index.isEven ? 1.2 : 1.0);
                          },)
                  ],],);
  }
}

提前谢谢!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。