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 (将#修改为@)